我有first.html
:
{% block title %}
hi there
{% endblock %}
{% block content %}
blah-blah
{% endblock %}
{% block footer %}
bye
{% endblock %}
和second.html
。
如何将所有 first.html
页面包含到 second.html
并补充 content
block ,如下所示:
hi there
blah-blah
this text is from second.html
bye
我已经尝试过
{% extends "first.html" %}
this text is from second.html
(只是没有添加任何内容)和
{% extends "first.html" %}
{% block content %}
this text is from second.html
{% endblock %}
( block 内容
被覆盖)。
最佳答案
您可以使用{{ block.super }}
[Django-doc]当您也想渲染原始内容时。例如:
{% extends 'first.html' %}
{% block content %}
<b>{{ block.super }}</b>
this text is from second.html
{% endblock %}
关于django - 如何补充父模板的 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58427924/