【发布时间】:2015-05-15 14:41:03
【问题描述】:
这快把我逼疯了。我做了一些奇怪的事情,似乎我的 TEMPLATE_DIRS 条目被忽略了。我只有一个 settings.py 文件,位于项目目录中,它包含:
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'web_app/views/'),
)
我将项目级模板放在 /templates 文件夹中,然后在我的应用程序文件夹中有用于不同视图类别的文件夹(例如身份验证视图、帐户视图等)。
例如,我的主索引页面视图位于 web_app/views/main/views_main.py 中,看起来像
from web_app.views.view_classes import AuthenticatedView, AppView
class Index(AppView):
template_name = "main/templates/index.html"
AppView 只是 TemplateView 的扩展。这是我的问题:当我尝试访问该页面时,我得到一个 TemplateDoesNotExist 异常,而真正让我困惑的部分是 Template-Loader Postmortem:
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
C:\Python34\lib\site-packages\django\contrib\admin\templates\main\templates\index.html (File does not exist)
C:\Python34\lib\site-packages\django\contrib\auth\templates\main\templates\index.html (File does not exist)
为什么不搜索“模板”和“web_app/views”目录?我已经通过调试器和views_main.py 中的断点检查了设置,看起来它们就在那里。有没有人遇到过类似的问题?谢谢。
【问题讨论】: