【发布时间】:2012-07-10 11:16:40
【问题描述】:
我知道很多人都问过这个问题,但是尽管对我的模板目录的路径进行了硬编码,但我似乎无法让 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 没有被使用(从它的样子来看)
【问题讨论】:
-
我假设您使用的是 Windows?
-
您是否已将项目路径添加到 python sys 路径中?
-
不,我使用的是 OS X...我没有将项目路径添加到 python sys 路径,我该怎么做?
-
我应该提到我使用的是 runserver 测试参数而不是 apache 或 nginx 来加载网页
标签: python django django-templates