【发布时间】:2021-10-26 12:42:42
【问题描述】:
我有一个带有<footer> 的layout.html 页面,我想在几乎所有使用{% extends "layout.html %} 的页面中显示它。只有在用户个人资料页面中,页脚才会有所不同。我该怎么做?
【问题讨论】:
我有一个带有<footer> 的layout.html 页面,我想在几乎所有使用{% extends "layout.html %} 的页面中显示它。只有在用户个人资料页面中,页脚才会有所不同。我该怎么做?
【问题讨论】:
您可以在布局页面中实现页脚块并相应地覆盖它:
{# layout.html #}
...
<div class="container">
...
{% block app_content %}{% endblock %}
{# block exists for all child templates #}
{% block footer %}{% endblock %}
</div>
...
{# profile.html #}
{% extends "layout.html" %}
{# the footer will automatically be placed inside container #}
{# you can override app_content for the body #}
{% block app_content %}...{% endblock %}
{% block footer %}{% include "profile_footer.html" %}{% endblock %}
{# footer.html #}
{# won't be included in profile.html #}
<footer>my footer</footer>
{# profile_footer.html #}
{# will be included in profile.html #}
<footer>profile footer</footer>
对于不需要页脚的任何页面,只需忽略该块
【讨论】: