Joody
Joody

Reputation: 13

TemplateDoesNotExist at / templates/main/index.html

Start to learn django from guide. And get this error every time.

TemplateDoesNotExist at / templates/main/index.html

I read about this error from official DJango documentation, but I couldn't find enter from situation

my project

my project's ways

settings.py

from pathlib import Path


BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = 'django-insecure-s%$#ykq62b_1q)#574(c7djut6bn66m5!i+3x&ypj*2h^k&%_f'


DEBUG = True

ALLOWED_HOSTS = []




INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main',
]

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

ROOT_URLCONF = 'taskmanager.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',
                'main'
            ],
        },
    },
]

WSGI_APPLICATION = 'taskmanager.wsgi.application'




DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}




AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]




LANGUAGE_CODE = 'ru'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True




STATIC_URL = '/static/'




DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

taskmanger\urls.py

from django.urls import path, include

urlpatterns = [
    path('', include('main.urls')),
]

main\urls.py

from django.urls import path
from . import views

urlpatterns = [ path('', views.index),

]

views.py

from django.shortcuts import render


def index(request):
    return render(request, 'main/index.html')

Upvotes: 1

Views: 724

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477230

The Django template engines sees the templates/ directories of the apps as root directories, given you set APP_DIRS=True [Django-doc].

This thus means that you should not mention the templates/ directory but work with:

from django.shortcuts import render

def index(request):
    return render(request, 'main/index.html')

Upvotes: 0

Related Questions