如何在 html 中动态命名标签,以便稍后与它们关联?
How to dynamically name tags in html so to relate to them later?
我应该如何在 template.html 中命名我的 select 标签,以便能够在每次收到 POST 时在 views.py 中分别指出它们] 消息?
<div style="display: inline-block;">
{% for type in range( form.typesCount ) %}
<div>
<select name="???">
{% for format in formats %}
<option value="{{format}}"> {{ format }}</option>
{% endfor %}
</select>
</div>
{% endfor %}
</div>
您可以使用 loop.index
,它是 returns Jinja for
中当前迭代索引循环的整数。例如:
{% for type in range( form.typesCount ) %}
<select name="my-select-{{loop.index}}">
...
</select>
{% endfor %}
我应该如何在 template.html 中命名我的 select 标签,以便能够在每次收到 POST 时在 views.py 中分别指出它们] 消息?
<div style="display: inline-block;">
{% for type in range( form.typesCount ) %}
<div>
<select name="???">
{% for format in formats %}
<option value="{{format}}"> {{ format }}</option>
{% endfor %}
</select>
</div>
{% endfor %}
</div>
您可以使用 loop.index
,它是 returns Jinja for
中当前迭代索引循环的整数。例如:
{% for type in range( form.typesCount ) %}
<select name="my-select-{{loop.index}}">
...
</select>
{% endfor %}