2
是否可以編寫一個模板標籤來檢查列表的內容?Django:如果在列表模板標籤
目前我有以下檢查從5到13,但這是非常詳細的,我將需要這樣做九次。
{% if wizard.steps.current == '5' %}
<img src="{% static "survey/images/pathtwo/" %}{{display_image}}"/>
<section>
<span class="tooltip"></span>
<div id="slider"></div>
<span class="volume"></span>
</section>
{% endif %}
{% if wizard.steps.current == '6' %}
<img src="{% static "survey/images/pathtwo/" %}{{display_image}}"/>
<section>
<span class="tooltip"></span>
<div id="slider"></div>
<span class="volume"></span>
</section>
{% endif %}
...
...
我已經試過
{% if wizard.steps.current in ['5','6','7','8','9','10','11','12','13'] %}
<img src="{% static "survey/images/paththree/" %}{{display_image}}" />
<section>
<span class="tooltip"></span>
<div id="slider"></div>
<span class="volume"></span>
</section>
{% endif %}
但得到一個錯誤
異常值:無法解析餘: '[' 5' , '6', '7' '','8','8','8','10','11','12','13']'''''''''''''' '10','11','12','13']'
有什麼想法?
在您的視圖中定義列表並執行'{$ if var in list%}' – Peter 2014-09-11 11:34:42