Django中的TemplateDoesNotExist(1.9)

时间:2017-08-09 09:08:29

标签: django templates

我已经在本地开发环境(vagrant box / ubuntu trusty)中安装了一个Django项目,该项目使用了几个在settings.py文件中正确加载的应用程序。

当我尝试运行应用程序(python manage.py runserver 0.0.0.0:8000)时,我得到:

TemplateDoesNotExist at /
geodash/maps/base.yml


Django tried loading these templates, in this order:

Using engine django:
django.template.loaders.filesystem.Loader: /home/vagrant/sparc2.git/sparc2/templates/geodash/maps/base.yml (Source does not exist)
django.template.loaders.app_directories.Loader: /home/vagrant/.venvs/sparc2/local/lib/python2.7/site-packages/django/contrib/admin/templates/geodash/maps/base.yml (Source does not exist)
django.template.loaders.app_directories.Loader: /home/vagrant/.venvs/sparc2/local/lib/python2.7/site-packages/django/contrib/auth/templates/geodash/maps/base.yml (Source does not exist)
django.template.loaders.app_directories.Loader: /home/vagrant/.venvs/sparc2/local/lib/python2.7/site-packages/django/contrib/gis/templates/geodash/maps/base.yml (Source does not exist)
django.template.loaders.app_directories.Loader: /home/vagrant/.venvs/sparc2/local/lib/python2.7/site-packages/pinax_theme_bootstrap/templates/geodash/maps/base.yml (Source does not exist)
django.template.loaders.app_directories.Loader: /home/vagrant/.venvs/sparc2/local/lib/python2.7/site-packages/django_forms_bootstrap/templates/geodash/maps/base.yml (Source does not exist)
django.template.loaders.app_directories.Loader: /home/vagrant/.venvs/sparc2/local/lib/python2.7/site-packages/autocomplete_light/templates/geodash/maps/base.yml (Source does not exist)
django.template.loaders.app_directories.Loader: /home/vagrant/.venvs/sparc2/local/lib/python2.7/site-packages/leaflet/templates/geodash/maps/base.yml (Source does not exist)
django.template.loaders.app_directories.Loader: /home/vagrant/sparc2.git/sparc2/templates/geodash/maps/base.yml (Source does not exist)

预期确实不存在于任何这些路径中。但它确实存在于具有此路径的另一个文件夹中:

/home/vagrant/geodash-framework-django.git/geodash/templates/geodash/maps

如何在settings.py文件中包含此内容?

1 个答案:

答案 0 :(得分:1)

编辑settings.py并在以下位置添加所需目录:

TEMPLATES = [
    # ...
    {
        'DIRS': 'the/path/to/the/required/directory',
    },
    # ...
]

编辑:关于你的评论

如果应用已添加到INSTALLED_APPS中的settings.py并且在目录templatetags中包含自定义标记,那么您应该可以使用以下内容在模板中加载它们:

{% load my_custom_templatetag %}

如果这不起作用,请尝试在settings.py

中指定templatetags库
TEMPLATES = [
    # ...
    {
        'DIRS': 'the/path/to/the/required/directory',
        'OPTIONS': {
            # ...
            'libraries': 'my_app.templatetags.my_custom_templatetag',
        },
    },
    # ...
]

my_app替换为应用名称,将my_custom_templatetag替换为代码名称。