我有一个包含另一个模板的模板。这包括模板中有块标签。Django - 包含模板中的块标签被调用模板覆盖
例子:
base.html文件
BASE
{% block title %}Base Title{% endblock %}
{% block content %}{% endblock %}
template1.html
{% extends 'base.html' %}
{% block title %}Extended Title{% endblock %}
{% block content %}
Extended content
{% include 'include.html' %}
{% endblock %}
include.html
{% block title %}Include Title{% endblock %}
{% block another_content %}Include Content{% endblock %}
我很期待是,如果我渲染模板.html我应该得到,我1.1.1
BASE
Extended Title
Extended content
Include Title
Include Content
但在做我其实得到这个,当我切换到1.2.1和1.2.3:
BASE
Extended Title
Extended Content
Extended Title
Include Content
正如你所看到的,在include.html标题块被替换为template1.html的标题栏。这种替换只发生在块名称相同的情况下,所以如果我改变include.html中的标题块,这不会发生。在我看来,它是包括并在同一时间扩展?任何人都知道这是否预期/我做错了什么?
它还挺我所上面说:) – bx2 2010-09-28 09:25:14