表单中有一个select字段,现在我需要迭代该字段中的选项.
{{ form.myselect }}
给了我这个:
<select name="myselect" id="id_myselect">
<option value="" selected="selected">---------</option>
<option value="2">Item 1</option>
<option value="3">Item 2</option>
...
</select>
现在我需要为选项添加一些属性,因此我需要:
<select name="myselect" id="id_myselect">
{% for x in form.myselect %}
<option value="{{ x.id }}">{{ x.name }}</option>
{% endfor %}
</select>
但是有一个错误:
Caught TypeError while rendering: 'BoundField' object is not iterable
我试了form.myselect.all
,form.myselect.option_set
,但是一无所获