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

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

问题描述

我不能在Django 1.7中呈现任何html页面。我的'index.html'位于 project / seatalloc / templates / index.html 中,我的view.py位于 project / seatalloc / views中。 py 看起来像:

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

项目/项目/设置。 py设置模板dir:

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


urls。 py:

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



我试图严格遵循这些文件,但是不知道Django是否检测到这个文件,为什么我得到Tem plateDoesNotExist at / seatalloc / error。我是Django的新手,有人可以帮忙。

解决方案

如果在你的情况下,你会得到一个TemplateDoesNotExist错误,调试页面状态文件存在通常存在的模板旁边(总是?)意味着此模板是指无法找到的另一个模板。



在您的case.html包含一个声明( {%extends%},{%include%},... )引用另一个模板Django找不到。不幸的是,从Django 1.8.3开始,调试页面总是命名基础模板,而不是Django找不到的模板。


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 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)),
)

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.

解决方案

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.

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天全站免登陆