我已经构建了我的应用程序Django(Django 1.8),如下所示。 当我在app1中尝试模板或app2在我的应用程序的base.html中扩展base.html时,我收到此错误。
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" %}
这是我的项目的结构
/projekt_folder
template
base.html
/app1
/template
base.html <-- {% extends "base.html" %}
/app2
/template
base.html <-- {% extends "base.html" %}
您需要告诉Django模板文件夹( projekt_folder/template
)的附加位置是什么,它不在已安装的应用程序下,在设置文件的顶部添加以下行:
import os
PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))
然后在TEMPLATES
设置var中设置DIRS
:
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',
],
},
},
]