Ad

TemplateDoesNotExist, Registration/login.html Django

- 1 answer

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')),
Ad

Answer

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'
Ad
source: stackoverflow.com
Ad