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

查看:610
本文介绍了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))

主文件夹内是templates文件夹和应用程序文件夹。我使用将应用程序放在与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 ().

如果我在TEXTLATE_DIRS的settings.py页面上打印了一个print语句,那么我可以正确地打印出TEMPLATE_DIRS ...所以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

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

:(

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

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