[Django]-TemplateDoesNotExist in project folder django 1.8

16πŸ‘

βœ…

You need to tell Django what is the additional location of your template folder (projekt_folder/template) which is not under installed apps, add following lines at top of your settings file:

import os

PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))

Then set DIRS in TEMPLATES setting var:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(PACKAGE_ROOT, 'template')],
        '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',
            ],
        },
    },
]
πŸ‘€Aamir Rind

0πŸ‘

Django 3.1.5:
You need to tell Django template engine where to look for your base.html template by adding it’s path in the DIRS like this :

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
   
    # Build paths inside the project like this: BASE_DIR / 'subdir'.
    # BASE_DIR in your case is '/projekt_folder'
    'DIRS': [
        BASE_DIR / 'template'
    ],
    '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',
        ],
    },
},]
πŸ‘€Blanklob

Leave a comment