Django 模板不存在错误,尽管它显示“文件存在" [英] Django Template does not exist error, although it shows 'file exists'

查看:25
本文介绍了Django 模板不存在错误,尽管它显示“文件存在"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 Django 1.7 中呈现任何 html 页面.我的index.html"在project/seatalloc/templates/index.html"中,而我在 project/seatalloc/views.py 中的 view.py 看起来像:

I am not able to render any html pages in Django 1.7. My 'index.html' is in 'project/seatalloc/templates/index.html' and my view.py in project/seatalloc/views.py looks like:

 def index(request):
       return render(request, 'index.html', dirs=('templates',)) 

project/project/settings.py 设置了模板目录:

project/project/settings.py has templates dirs set:

TEMPLATE_DIRS = (
    '/Users/Palak/Desktop/academics/sem3/cs251/lab11/project/seatalloc/templates',

)

urls.py:

urlpatterns = patterns('',
    url(r'^seatalloc/', include('seatalloc.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

我已尝试严格按照文档进行操作,但无法弄清楚 Django 是否检测到该文件,为什么我在/seatalloc/处收到 TemplateDoesNotExist 错误.我是 Django 的新手,有人可以帮忙吗.

I have tried to follow the documentation strictly, yet can't figure out if Django detects the file, why am I getting TemplateDoesNotExist at /seatalloc/ error. I am new to Django, could someone please help.

推荐答案

如果 - 就像您的情况一样 - 您收到 TemplateDoesNotExist 错误并且调试页面在相关模板旁边指出文件存在",这通常(总是?)表示此模板引用了另一个找不到的模板.

If - as in your case - you get a TemplateDoesNotExist error and the debug page states "File exists" next to the template in question this usually (always?) means this template refers to another template that can't be found.

在您的情况下,index.html 包含一个语句 ({% extends %}, {% include %}, ... ) 引用另一个 Django 找不到的模板.不幸的是,从 Django 1.8.3 开始,调试页面总是命名基本模板,而不是 Django 找不到的模板.

In your case, index.html contains a statement ({% extends %}, {% include %}, ... ) referring to another template Django cannot find. Unfortunately, as of Django 1.8.3, the debug page always names the base template, not the one Django can't find.

这篇关于Django 模板不存在错误,尽管它显示“文件存在"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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