我的模板中有:
<select name="meetingTimeDay">
{% for k in days2 %}
<option value="{{ forloop.counter0 }}"{% ifequal c.meetingTime|date:"w", forloop.counter0 %}selected="selected"{% endifequal %}>{{ k }}</option>
{% endfor %}
</select>
其中days2是:
days2 = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')
但是ifequal不起作用。我渲染出forloop.counter0和meetingTime | date:“w”,1天将在视觉上匹配。我认为这可能是一个铸造问题。
任何想法?
答案 0 :(得分:0)
删除分隔值的逗号
{% ifequal c.meetingTime|date:'w' forloop.counter0 %}
if标签也有很长的路要走
{% if c.meetingTime|date:'w' == forloop.counter0 %}
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#if