Ad

TemplateDoesNotExist At /accounts/login/ Login.html

Imm trying to use default django login system. It gives me error that my login.html templates does not exist.

I have my login templates saved in a root directory..> templates>registration>login.html

Imm using custom user models and token authentication..

Here's what i tried ..>

account urls.py

from django.contrib.auth import views as auth_views
from django.conf.urls import url
from django.urls import path 


urlpatterns = [
    path("login/", auth_views.LoginView.as_view(template_name = "login.html"), name='login'),
    path("logout/", auth_views.LogoutView.as_view(), name='logout'),
]

Main App Urls.py

from django.contrib import admin
from django.urls import path, include

from rest_framework.urlpatterns import format_suffix_patterns

from django.conf.urls.static import static
from django.conf import settings
from django.conf.urls import url

from articles.views import ArticleDetail, ArticleList
from account.views import AccountList

from rest_framework.authtoken import views


urlpatterns = [
    path('admin/', admin.site.urls),
    path('article/', ArticleList.as_view()),
    path('article/<int:pk>/', ArticleDetail.as_view()),
    path('accounts/', AccountList.as_view()),
    path('accounts/', include('account.urls'))
]

urlpatterns += static(settings.MEDIA_URL,
                              document_root=settings.MEDIA_ROOT)

urlpatterns = format_suffix_patterns(urlpatterns)

Templates dir in settings.py#

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',
            ],
        },
    },
]

Does using a custom user models and Token auth effects default login system ?

Ad

Answer

you have to change the template_name and everything will work

template_name = "registration/login.html"
Ad
source: stackoverflow.com
Ad