将Django base.html模板划分为header,content和footer.html

San*_*jay 4 django django-templates

嗨,我已将Django Admin模板扩展到我的app/templates/admin目录..在该目录中我有base.html哪些内容

<header> header content<header>
<body> body Content </body>
<footer> Footer Content</footer>
Run Code Online (Sandbox Code Playgroud)

所以我创建header.html了包含的内容

{% extends "admin/base_site.html" %}
<!-- I also tried to include base.html here-->
{% block header %}
 Header Html here...
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

并替换base.html为以下内容

{% block header %}  {% endblock %}
<body> body content </body>
<footer> Footer Content </footer>
Run Code Online (Sandbox Code Playgroud)

但标题内容没有加载..所以请建议.

Pra*_*edi 7

在使用header.html的块头之前使用include.

而且您不需要创建一个块来将HTML文件包含到另一个中.在header.html文件中,只需编写头文件的代码即可.像这样 :

{% extends "admin/base_site.html" %}

     Header Html here...
Run Code Online (Sandbox Code Playgroud)

并且,在您的base.html中尝试以下代码:

{% include "templates/header.html" %}

    <body> body content </body>
    <footer> Footer Content </footer>
Run Code Online (Sandbox Code Playgroud)

注意:根据您的header.html位置使用"templates/header.html"