K
K
kingslayer2021-07-21 21:13:57
Django
kingslayer, 2021-07-21 21:13:57

Why does the TemplateDoesNotExist error occur?

urls.py

from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('about/', views.about)
]

views.py
from django.http import HttpResponse
from django.shortcuts import render
def about(request):
    return render(request, 'untitled2.html')

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-07-22
@kingslayer

kingslayer in TEMPLATES[0]['DIRS'] you need to specify the full path to the folder, for example for django < 3.1 and for django > 3.1
os.path.join(BASE_DIR, 'templates')
BASE_DIR / 'templates'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question