-1
最初我在我的Django项目中只有一个应用程序,模板由index.html,detail.html和layout.html组成...索引和详细文件扩展了布局。他们都住在同一个目录([app1]/templates/[app1]/),它可以找到所有的文件。Django无法找到模板目录?
现在我有了第二个应用程序,我想重新使用layout.html ...我决定将一个模板目录关闭django项目的基础,并将它放在那里。这里是我的目录结构是什么样子现在:
<basepath>/<django_project>/templates/shared
<basepath>/<django_project>/<app1>/templates/<app1>
<basepath>/<django_project>/<app2>/templates/<app2>
我更新了我的settings.py:
TEMPLATE_DIRS = (
'/full/path/to/<django_project>/<app1>/templates',
'/full/path/to/<django_project>/<app2>/templates',
'/full/path/to/<django_project>/templates',
)
在 '共享' DIR我有...的layout.html从APP1或APP2模板迪尔斯,我有index.html文件以及在文件顶部的“扩展”行读取:
{% extends "shared/layout.html" %}
然而,当我尝试加载应用程序查看,它得到一个错误,它不能找到shared/layout.html
TemplateSyntaxError at/
Caught TemplateDoesNotExist while rendering: shared/layout.html
任何想法我失踪?这应该是相当简单的,我必须忽略一些非常明显的东西?
是否可以显示TEMPLATE_LOADERS设置? – 2012-07-19 13:54:55
或权限问题? – Konstant 2012-07-19 13:57:28
另请注意,如果您在设置的“TEMPLATE_LOADERS”(这是默认设置)中启用了'django.template.loaders.app_directories.Loader',那么您不需要添加提及的“per-application”模板dir在'TEMPLATE_DIRS'中。 – 2012-07-19 14:07:14