Djangov1.4.3の下で
以下のDjangoテンプレートケース1のifステートメントが、ifステートメントがTRUEであるかどうかに関係なく、常にブロックステートメントの内容を表示するのはなぜですか?
テンプレートのifステートメントの前にブロックステートメントが常に実行されますか?(多分私はドキュメントでこれを見逃しました。)
View.py(map_urlはテスト目的で意図的に「提供されていない」ことに注意してください):
def post_address(request):
return render_to_response(
'record/post_address.html',
{'form': form},
context_instance=RequestContext(request)
)
base_integrated_form.html親テンプレートに含まれるもの
{% block after_form %}
{% endblock after_form %}
post_address.html(2つのケース)Djangoテンプレートケース1 :(ブロックステートメントをifステートメントにネストすると、ブロックステートメントのコンテンツは、map_url
提供されているかどうかに関係なく、常にブラウザーに表示されます。)
{% extends "base_integrated_form.html" %}
{% if map_url %}
{% block after_form %}
<div style="max-width:555px; height:240px; margin-left:auto; margin-right:auto;">
<iframe id="map" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="{{ map_url }}" style="border: 0px solid black"></iframe>
</div>
{% endblock after_form %}
{% endif %}
Djangoテンプレートケース2(ブロックステートメントにifステートメントをネストすると、提供されている場合にのみ、ブラウザーにブロックステートメントの内容が表示されますmap_url
。):
{% extends "base_integrated_form.html" %}
{% block after_form %}
{% if map_url %}
<div style="max-width:555px; height:240px; margin-left:auto; margin-right:auto;">
<iframe id="map" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="{{ map_url }}" style="border: 0px solid black"></iframe>
</div>
{% endif %}
{% endblock after_form %}