我有一个layout.html
页面,我想在几乎所有使用{% extends "layout.html %}
的页面中显示<footer>
。只有在用户配置文件页面的页脚将是不同的。我该怎么做呢?
您可以在布局页面中实现页脚块并相应地覆盖它:
{# 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>
对于任何你不想要页脚的页面,只要省略