Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TemplateDoesNotExist, registration/login.html Django

Am using Django Authentication Model. The problem is when i visit /accounts/login, i get TemplateDoesNotExist: registration/login.html error message. Now the problem is i already specified a template for the LoginView.

Here is my accounts/urls.py file

from django.urls import path
from django.contrib.auth import views as auth_views
from . import views
app_name = 'accounts'
urlpatterns = [
    path('login/',auth_views.LoginView.as_view(template_name='accounts/login.html'), name='login'),
    path('join/', views.SignupView.as_view(), name='join'),
    path('logout/', auth_views.LogoutView.as_view(), name='logout'),
]

The login template is located at accounts/templates/accounts/login.html

And here is the TEMPLATES

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
    },
},

]

My projects urls.py file has these

path('accounts/', include('django.contrib.auth.urls')),
path('accounts/', include('accounts.urls')),
like image 217
Gabriel Amaizu Avatar asked Jul 07 '18 17:07

Gabriel Amaizu


1 Answers

From your error message, it is expecting the login.html file is to be located within your accounts app templates/registration directory like this: accounts/templates/registration/login.html. That should fix your issue.

Also, add these two lines at the bottom of your settings.py file:

LOGIN_URL = 'login'
LOGOUT_URL = 'logout'
like image 114
Chuka_FC Avatar answered Oct 11 '22 02:10

Chuka_FC