Django应用程序在下游应用程序中不包括base.html模板

2024-10-01 15:48:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Django应用程序,我正在尝试设置一个基本html模板,其中包括页脚、导航栏等,我可以在整个网站上重复使用

我遇到的问题是,当我试图在下游应用程序模板文件夹和索引中包含我的基础模板时,我遇到了一个错误。我希望这是有道理的

在我的主根目录中我有templates/base.html,在我的应用程序中NewsBase/templates/NewsBase/index.html我有以下内容:

{% extends 'templates/base.html' %}

<body>
    <h1>NewsBase</h1>
</body>

只要删除extends块,我的路由/URL就可以正常工作,因为这个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

Tags: django模板应用程序homebaselibpackagesusr

热门问题