Django 找不到模板 [英] Django can't find template

查看:61
本文介绍了Django 找不到模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道很多人都问过这个问题,但尽管硬编码了我的模板目录的路径,但我似乎无法让 Django 找到我的模板.

I know many people have asked, this question, but despite hardcoding the path to my template directory I can't seem to get Django to find my template.

这里是settings.py

Here is 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文件:

This is the views.py file:

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 更改了默认文件结构.

Inside the main folder is the templates folder and the app folder. I use to put the apps in the same folder as settings.py but it appears django 1.4 has changed the default file structure.

我的错误是:

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 列为 ().

Update:
My logs for the webpage list the TEMPLATE_DIRS as ().

如果我在 TEMPLATE_DIRS 的 settings.py 页面上放置了一个打印语句,我会适当地打印出 TEMPLATE_DIRS...

If I put a print statement on the settings.py page for the TEMPLATE_DIRS I get a printout of the TEMPLATE_DIRS appropriately... so somehow the TEMPLATE_DIRS isn't being used (from what it looks like)

推荐答案

我在 settings.py 中添加了一个额外的 TEMPLATE_DIR

I had added in an extra TEMPLATE_DIR in the settings.py

:(

这篇关于Django 找不到模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆