TemplateDoesNotExist - 具有嵌套prj / apps / app1目录的Django 1.8普通加载器

时间:2015-04-27 10:47:58

标签: python django

我正在设置一个新的django 1.8项目,但我的应用模板未从app/template目录加载。常规视图片段:

return render_to_response('pcmanage/index.html', {
    'msg': msg,
    }, context_instance=RequestContext(request))

可能是一个辛辣的细节。我的应用程序位于:

project
    apps/app1
    apps/app2

有效的路径(取自project):

templates/pcmanage/index.html

无法工作的路径:

apps/pcmanage/templates/pcmanage/index.html

pcmanage/templates/pcmanage/index.html

我的设置文件位于项目基础的设置目录中。通过以下方式发起:

export DJANGO_SETTINGS_MODULE=settings.settings_debug

重要设置信息:

INSTALLED_APPS += (
    'pcmanage',
)

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

我还尝试将apps.pcmanage添加到INSTALLED_APPS,但没有运气。

模板加载器postmortem:

Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
/path2env/project/templates/wpcmanage/pillar_view.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/path2env/lib/python2.7/site-packages/django/contrib/auth/templates/wpcmanage/pillar_view.html (File does not exist)
/path2env/lib/python2.7/site-packages/bootstrap3/templates/wpcmanage/pillar_view.html (File does not exist)
/path2env/lib/python2.7/site-packages/django_admin_bootstrapped/templates/wpcmanage/pillar_view.html (File does not exist)
/path2env/lib/python2.7/site-packages/django/contrib/admin/templates/wpcmanage/pillar_view.html (File does not exist)
/path2env/lib/python2.7/site-packages/django/contrib/admindocs/templates/wpcmanage/pillar_view.html (File does not exist)
/path2env/project/apps/wpcmanage/templates/wpcmanage/pillar_view.html (File exists)
/path2env/lib/python2.7/site-packages/debug_toolbar/templates/wpcmanage/pillar_view.html (File does not exist)

我很乐意发布所需的任何其他信息。

1 个答案:

答案 0 :(得分:2)

问题出在模板文件本身。

它从旧应用

扩展了一个不存在的模板
{% extends 'otherapp/pillar__base.html' %}

{% block content %}
<h1>Salty Front</h1>

    {{ msg }}

{% endblock %}