2👍
✅
Use the forloop.counter variable
{% for p in products %}
<input type="number" name="name-{{forloop.counter}}-arg1" value="{{p.arg1}}" size="12"/>
<input type="number" name="name-{{forloop.counter}}-arg2" value="{{p.arg2}}" size="12"/>
{% endfor %}
The forloop.counter
is 1-indexed. There is also the forloop.counter0
for indices
starting with 0.
Are you sure though that django formsets isn’t what you need?
Source:stackexchange.com