我有一个具有以下结构的项目:
project
project
static/
templates
project
base.html
__init__.py
.....
events
static/
templates
events
events.html
__init__.py
models.py
.....
我想延长base.html
在events.html
我尝试了:
{% extends "project:project/base.html" %}
但是出现以下错误:
Exception Type: TemplateDoesNotExist
Exception Value: project:project/base.html
还尝试了:
{% extends "base.html" %}
但是返回相同的错误:
Exception Type: TemplateDoesNotExist
Exception Value: base.html
在INSTALLED_APPS
我有:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'events',
'project',
)
TEMPLATE_DIRS
和BASE_DIR
:
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
在TEMPLATE_LOADERS
我有:
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
您TEMPLATE_DIR
已设置为project/templates
,而不是project/templates/project
。
由于base.html
in中没有project/templates
,因此Django返回错误。
您可以前进base.html
至project/templates
,也可以通过编写以下内容进行引用:
{% extends "project/base.html" %}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句