I have structured my application Django (Django 1.8) as shown below. When I try template in app1 or app2 extends base.html in base.html of my application, I get this error.
TemplateDoesNotExist at /
base.html
Error during template rendering
In template /myProject/project_folder/app1/templates/app1/base.html, error at line 1
{% extends "base.html" %}
Here is structure of my project
/projekt_folder
template
base.html
/app1
/template
base.html <-- {% extends "base.html" %}
/app2
/template
base.html <-- {% extends "base.html" %}
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',
],
},
},
]