【发布时间】:2020-04-30 22:33:59
【问题描述】:
我有一个 Django 应用程序,我试图在其中设置一个基本 html 模板,以包括页脚、导航栏等,我可以在整个站点中重复使用这些模板。
我遇到的问题是,当我尝试将基本模板包含在下游应用程序模板文件夹和索引中时出现错误。我希望这是有道理的。
在我的主根目录中,我有templates/base.html,在我的应用程序NewsBase/templates/NewsBase/index.html 中,我有以下内容:
{% extends 'templates/base.html' %}
<body>
<h1>NewsBase</h1>
</body>
只要删除 extends 块,我的路由/网址就可以正常工作,因为此 html 呈现。
如何在解决方案中正确包含来自其他应用的 base.html 模板?
Base.html
<!DOCTYPE HTML>
{% load staticfiles %}
{% block content %}{% endblock %}
{% include "footer.html" %}
</html>
错误:
TemplateDoesNotExist at /
templates/base.html
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.11.29
Exception Type: TemplateDoesNotExist
Exception Value:
templates/base.html
Exception Location: /home/etherk1ll/.local/lib/python2.7/site-packages/django/template/engine.py in find_template, line 148
Python Executable: /usr/bin/python
Python Version: 2.7.17
Python Path:
['/home/etherk1ll/Development/python_projects/NewSite',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/etherk1ll/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
Server time: Thu, 30 Apr 2020 22:30:51 +0000
【问题讨论】: