我在我的Django项目中出现了一个奇怪的TemplateDoesNotExist错误。加载器实际上找到一个模板文件(它也存在,我想打电话!)。这是输出: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:
[...]/anaconda3/lib/python3.4/site-packages/django/contrib/admin/templates/osm/index.html (File does not exist)
[...]/anaconda3/lib/python3.4/site-packages/django/contrib/auth/templates/osm/index.html (File does not exist)
[...]/projekt/osm/templates/osm/index.html (File exists)
[...]/projekt/flotte/templates/osm/index.html (File does not exist)
即使找到文件,为什么会抛出错误?
编辑:经过一些测试,似乎作为致以base.html
而独立的HTML模板工作,不工作的所有HTML模板:
{% extends 'base.html' %}
{% load static %}
{% block main_content %}
[...]
我base.html
位于[...]/projekt/static/templates
。该路径在TEMPLATE_DIRS中定义。很确定这个工作之前更新到Django的1.8.2! :(
如何使项目模板路径[...]/projekt/static/templates
我的设置:[全看http://pastebin.com/rn2hSj5Y]
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
#Template location
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, "static", "templates"),
#os.path.join(PROJECT_PATH, "osm", "templates", "osm"),
#os.path.join(PROJECT_PATH, "flotte", "templates", "flotte"),
)
我相应的视图:
def index(request):
# Request the context of the request.
# The context contains information such as the client's machine details, for example.
context = RequestContext(request)
context_dict = {'boldmessage': "I am bold font from the context"}
return render_to_response('osm/index.html', context_dict, context)
你检查了文件的权限吗? –
是的,''/ projekt/osm/templates/osm/index.html'是可读的:'-rwxrwxr-- 1个用户plugdev 982 2014年10月5日index.html *' – Klaster
我猜你是不使用Django 1.8 - 你在什么版本? 1.8更改模板设置。 – FlipperPA