Django页脚和每页上的标题{%extends}

enc*_*ypt 17 html css django

所以我试图在我的网站的每个页面上添加页脚和标题.我制作了一个base.html文件,其中包含网站的总体布局.

在我的about.html页面中,我做了:

{% extends "public/base.html" %}

<h1>Content goes here</h1>
Run Code Online (Sandbox Code Playgroud)

我可以看到我的页眉和页脚,但如何显示内容.我想在about.html页面中输入内容.这里的内容没有显示在中间.

Dan*_*man 30

您需要在base.html中定义一个块并在about.html中填充它.

base.html文件:

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

about.html

{% extends "public/base.html" %}

{% block content %}
<h1>Content goes here</h1>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

这一点在本教程中都有详细解释.

  • 所以CSS被认为是一个静态文件,所以你会使用:`{%load staticfiles%}`.更多信息:https://docs.djangoproject.com/en/1.8/howto/static-files/此外,如果是,请将答案标记为正确. (2认同)

cha*_*ndu 9

{% extends "public/base.html" %}
{% block content %}
<h1>Content goes here</h1>
{% endblock %}
Run Code Online (Sandbox Code Playgroud)

或者只是about.html在主html中创建并包含它.

例:

    {% extends "public/base.html" %}
    {% block content %}
       "Your code"
    {% include "core/about.html" %}
    {% endblock %}
Run Code Online (Sandbox Code Playgroud)