【发布时间】:2016-03-07 16:02:42
【问题描述】:
我在 django 模板页面中有这段代码
<select class="selectpicker datatable-column-control" multiple
{% for q_group in question_groups %}
<optgroup label="{{ q_group.name }}">
{% for q in q_group.questions %}
<option value="{{ forloop.counter0 }}">{{ q.title }}</option>
{% endfor %}
</optgroup>
{% endfor %}
我想要在每次迭代中增加的每个选项标签的值。如果我有 10 个选项标签,那么它们的值将是 0 到 9。
forloop.counter0 不能满足我的需要,因为当外循环完成一次时,内循环计数器初始化为 0。
【问题讨论】:
标签: python django django-templates