ブロックを継承する 2 つの子テンプレート ファイルの場合、{{ block.super }}
は解決されません。
Python 2.5.2、Django 1.0、Windows XP SP3
関連するファイルのサンプル スケルトン コード:
base.html
item_base.html
show_info_for_all_items.html
show_info_for_single_item.html
ファイル :base.html
{% block content %}
{% endblock %}
ファイル :item_base.html
{% extends "base.html" %}
{% block item_info %}
Item : {{ item.name }}<br/>
Price : {{ item.price }}<br/>
{% endblock %}
ファイル :show_info_for_all_items.html
{% extends "item_base.html" %}
{% block content %}
<h1>info on all items</h1>
<hr/>
{% for item in items %}
{% block item_info %}
{{ block.super }}
{% endblock %}
<hr/>
{% endfor %}
{% endblock %}
ファイル :show_info_for_single_item.html
{% extends "item_base.html" %}
{% block content %}
<h1>info on single item</h1>
{% block item_info %}
{{ block.super }}
{% endblock %}
{% endblock %}
show_info_for_all_items.html
アイテムのリストと各アイテムの情報を表示します。
show_info_for_single_item.html
アイテムの情報を含む単一のアイテムを示します。
show_info_for_all_items.html
show_info_for_single_item.html
アイテム情報を表示するための同じコードを共有するので、に移動しましitem_base.html
たblock item_info
しかし、動作{{ block.super }}
しません。空白として解決されます。show_info_for_all_items.html
show_info_for_single_item.html
{{ block.super }}
block item_info
コードを in からinitem_base.html
に戻すshow_info_for_all_items.html
と機能しますが、同じコードを 2 つのファイルshow_info_for_single_item.html
に複製する必要があります。block item_info
block.super の問題を解決できない場合、Django は INCLUDE => のようなものを提供するので、テンプレート ファイルのブロックを ( の代わりに){% INCLUDE "item_base.html" %}
含めることができますか?extends
block item_info
両方の html ファイルで重複しないようにするにはどうすればよいですか?