我有一個包含另一個模板的模板。這包括模板中有塊標籤。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