Как исправить эту ошибку: Template Does Not Exist ? Django

urls.py

from django.urls import path

from . import views

urlpatterns = [ 
    path('',views.home, name='home')
    
]

еще один urls.py

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

urlpatterns = [
    path('', include('subokLang.urls')),
    path('admin/', admin.site.urls),
]

settings.py - шаблоны

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

views.py

from django.shortcuts import render
from django.http import HttpResponse

def home(request):
    return render(request, 'templates/home.html')

Я застрял здесь, пробовал менять уже много, все равно не работает, 500(Шаблон не существует), какой правильный код?

Заранее спасибо!

В вашем файле settings.py:

внутри TEMPLATES, просто добавьте следующее:

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

Ex:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')], #Added here
        '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',
            ]
        },
    },
]
Вернуться на верх