Get specific fields from a formset
For the documentation开发者_高级运维, I'm able to display a formset as below
<table>
{{ formset }}
</table>
However, what if I want to format the layout manually? Like how it's done for ModelForms? How can I achieve this?
You can do form.field name, Example: {{ form.username }}
, django-display form template
{% for form in formset %}
{% for field in form %}
do something with {{ field }}
{% endfor %}
{% endfor %}
I do something like this.
{{ form.username.errors }}
<label for="id_username">Username:</label>
{{ form.username }}<br />
{{ form.password.errors }}
<label for="id_password">Password:</label>
{{ form.password }}
Or you could do if you didn't need to customize the label element
{{ field.username_tag }}: {{ form.username}}
精彩评论