TemplateDoesNotExist - 文件存在,没有权限问题 [英] TemplateDoesNotExist - file exists, no permissions issue
问题描述
在django中尝试呈现模板时,我收到此错误:
I'm receiving this error when trying to render a template in django:
TemplateDoesNotExist
...
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
这是我的settings.py条目:
Here's my settings.py entry:
SETTINGS_PATH = os.path.normpath(os.path.dirname(__file__))
TEMPLATE_DIRS = (
os.path.join(SETTINGS_PATH, 'template'),
)
这是我正在调用的视图:
Here's my view that's being called:
def handler(request):
if request.method == 'GET':
NewAppFormSet = modelformset_factory(Application)
return render_to_response(request, "template/apps.html",{"new_app_form":NewAppFormSet})
我试过ev可能的路径组合,调整权限等。真正的问题似乎在于模板加载程序,因为它们不会识别TEMPLATE_DIRS中阐述的任何路径。我已经硬编码了这个字符串,无济于事。我也以root身份运行 python manage.py runserver
。我正在失去...
I've tried every possible combination of paths, adjusting permissions, etc. The real issue seems to be with the template loaders, as they are not recognizing any paths set forth in TEMPLATE_DIRS. I've hardcoded this string, to no avail. I've also ran python manage.py runserver
with sudo / as root. I'm at a loss...
推荐答案
我不知道我遵循的示例指定了render_to_response快捷方式需要传递视图的请求对象,但是将其更改为:
I'm not sure what example I was following that specified the render_to_response shortcut method requires the views' request object to be passed, but it was as easy as changing it to:
return render_to_response("template/apps.html",{"new_app_form":NewAppFormSet()})
这篇关于TemplateDoesNotExist - 文件存在,没有权限问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!