我知道很多人都问过这个问题,但是尽管对我的模板目录的路径进行了硬编码,但我似乎无法让 Django 找到我的模板。
这是settings.py
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
#django.template.loaders.eggs.Loader',
)
TEMPLATE_DIRS = (
"/Users/full/path/to/marketing_site/templates",
)
这是views.py 文件:
def static (request, feature_page):
# this will get the appropriate feature page template.
template = loader.get_template('features/pricing.html')
c = RequestContext(request,{
})
return HttpResponse(template.render(c))
主文件夹内是模板文件夹和应用程序文件夹。我曾经将应用程序放在与 settings.py 相同的文件夹中,但似乎 django 1.4 更改了默认文件结构。
我的错误是:
TemplateDoesNotExist at /features/pricing
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/Library/Python/2.7/site-packages/django/contrib/auth/templates/feature_pricing.html (File does not exist)
更新:
我的网页日志将 TEMPLATE_DIRS 列为 ()。
如果我在 TEMPLATE_DIRS 的 settings.py 页面上放置一个打印语句,我会适当地打印出 TEMPLATE_DIRS ......所以不知何故 TEMPLATE_DIRS 没有被使用(从它的样子来看)