Ad

TemplateDoesNotExist At /project/login/ Registration/login.html

- 1 answer

When I try to go to my login page, I always get this:

TemplateDoesNotExist at /rubies/login/

registration/login.html

My login file is in the folder templates, just like all the other html files. I tried creating a register folder and putting it in, but it still didn't work!

Here is (part of) my settings.py file

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
      'project.apps.ProjectConfig',
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
]

 ROOT_URLCONF = 'project.urls'

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [],
    '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',
        ],
    },
},
]

WSGI_APPLICATION = 'project.wsgi.application'

And my urls.py :

from django.urls import path
from rubies import views
from django.contrib.auth import views as auth_views

app_name = 'rubies'

urlpatterns = [
    path('', views.index_view, name='index'),
    path('register/', views.register_view, name='register'),
    path('login/', auth_views.LoginView.as_view(), name='login'),
    path('users/<int:user_id>/', views.user_view, name='user'),
    path('users/<int:user_id>/stories/<int:story_id>/', views.story_view, name='story'),
]

Does anyone know what or where I am doing wrong? Thank you!

Ad

Answer

You should add the following to your TEMPLATES:

'DIRS': [os.path.join(BASE_DIR, 'templates'), ],

This means that Django will look at the templates from your project's /templates folder.

Ad
source: stackoverflow.com
Ad