需要使UI更有序,我可以有索引的形式在formset或访问形式ID?
<div class="card">
<div class="card-body">
<div id="form-container">
{% csrf_token %}
{{ formset1.management_form }}
{% for form in formset1 %}
<div class="test-form">
{% crispy form %}
</div>
{% endfor %}
<button id="add-form" type="button" class="btn btn-primary">Add Another Request
</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>
是的,你可以使用forloop。像这样在forloop中的计数器,可以将值赋给name或id
<div class="card">
<div class="card-body">
<div id="form-container">
{% csrf_token %}
{{ formset1.management_form }}
{% for form in formset1 %}
{% crispy form %}
</div>
{% endfor %}
<button id="add-form" type="button" class="btn btn-primary"> Add Another Request </button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</div>