2015-06-21 28 views
2

我在我的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) 
+0

你检查了文件的权限吗? –

+0

是的,''/ projekt/osm/templates/osm/index.html'是可读的:'-rwxrwxr-- 1个用户plugdev 982 2014年10月5日index.html *' – Klaster

+0

我猜你是不使用Django 1.8 - 你在什么版本? 1.8更改模板设置。 – FlipperPA

回答

0

如果OSM,拉弗洛特是应用程序,只需从TEMPLATE_DIRS中删除这两行:

os.path.join(PROJECT_PATH, "osm", "templates", "osm"), 
os.path.join(PROJECT_PATH, "flotte", "templates", "flotte"), 

因为它们已经被app目录加载器找到。 TEMPLATE_DIRS适用于非应用程序模板。

+0

嗨amr,谢谢你的回答。我试过这个,但是我找不到它有所作为。在更改settings.py以部署更改后,除了重新启动服务器之外,我还需要做些什么吗? – Klaster