简体   繁体   English

Django 1.8 忽略 DIRS,找不到模板

[英]Django 1.8 ignores DIRS, cannot find templates

Here is my TEMPLATES section in settings.py:这是我在 settings.py 中的 TEMPLATES 部分:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

I'm using template inside application directory and it works.我在应用程序目录中使用模板并且它有效。 But whenever I'm trying to extend it with layout from global templates directory (os.path.join(BASE_DIR, 'templates'), which exists, I tested), django raises TemplateDoesNotExist error.但是每当我尝试使用全局模板目录(os.path.join(BASE_DIR, 'templates'),它存在,我测试过)的布局扩展它时,django 就会引发 TemplateDoesNotExist 错误。 Here is Template-loader postmortem, which does not includes my DIRS directory:这是模板加载器事后分析,它不包括我的 DIRS 目录:

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
/usr/local/lib/python2.7/dist-packages/django/contrib/admin/templates/layouts/default.html (File does not exist)
/usr/local/lib/python2.7/dist-packages/django/contrib/auth/templates/layouts/default.html (File does not exist)
/home/foundation/public/foundation/foundation/event_request/templates/layouts/default.html (File does not exist)

**UPDATE: ** seems like apache loads django 1.5 instead of django 1.8. **更新:** 似乎 apache 加载 django 1.5 而不是 django 1.8。 This might be a problem.这可能是一个问题。

After log entry登录后

Using loader django.template.loaders.filesystem.Loader:使用加载器 django.template.loaders.filesystem.Loader:

loader should print all possible locations that it tried to find your template, like it was after similar log from app_directories loader. loader 应该打印它试图找到模板的所有可能位置,就像在app_directories loader 的类似日志之后一样。 If there is no paths here, double check if your TEMPLATES setting is defined correctly, is not overwritten somewhere later in your settings or other files and if Django is loading that settings file correctly.如果这里没有路径,请仔细检查您的TEMPLATES设置是否正确定义,是否未在您的设置或其他文件中的某个地方被覆盖,以及 Django 是否正确加载了该设置文件。

You can throw some exception to get 500 server error when DEBUG is set to True , on error page you will get handy list of all settings that Django sees.DEBUG设置为True ,您可以抛出一些异常以获得 500 服务器错误,在错误页面上,您将获得 Django 看到的所有设置的方便列表。

Also check if your WSGI server is loading proper version of django, older versions doesn't have TEMPLATE setting (it was splitted between multiple settings).还要检查您的 WSGI 服务器是否正在加载正确版本的 django,旧版本没有TEMPLATE设置(它被拆分为多个设置)。

Problem has to do with wrong virtualenv and actual use of Django 1.5.1 instead of 1.8.问题与错误的 virtualenv 和实际使用 Django 1.5.1 而不是 1.8 有关。 I'll save this post, maybe it will help someone with similar problem in future.我会保存这篇文章,也许它会帮助将来有类似问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM