Search code examples
djangodjango-authentication

TemplateDoesNotExist at /accountparents/login/


The signup.html is working fine but if i click the login and logout, The error show this:

    TemplateDoesNotExist at /accountparents/login/
        registration/login.html

I dont know where I can locate that registration/login.html

This is my settings.py

INSTALLED_APPS = [
    'accounts',
    'Homepage',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'Homepage/templates','accounts/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',
            ],
        },
    },
]

and this is my URLS.py

urlpatterns = [
   path('home/', Homepage.views.home, name='home'),
   path('login/', LoginView.as_view(template_name='Homepage/login.html'), name='login'),
   path('logout/', LoginView.as_view(template_name='Homepage/logout.html'), name='logout'),
   path('staff/', Homepage.views.staff, name='staff')
]

I save my login.html from Homepage/templates folder, I dont know where is the registration came from..


Solution

  • Change your urls.py patterns as

    from django.contrib.auth import views as auth_views
    urlpatterns = [
        path('home/', Homepage.views.home, name='home'),
        path('login/', auth_views.LoginView.as_view(template_name='Homepage/login.html'), name='login'),
        path('logout/', auth_views.LogoutView.as_view(template_name='Homepage/logout.html'), name='logout'),
        path('staff/', Homepage.views.staff, name='staff'),
    ]
    

    Create templates directory in each one of your app installed and do not create it in root project folder. Its not a good practise. Inside template directory. create one more directory by the name of app, inside which save all your templates.