开发者

Get specific fields from a formset

开发者 https://www.devze.com 2022-12-15 21:59 出处:网络
For the documentation开发者_高级运维, I\'m able to display a formset as below <table> {{ 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}}
0

精彩评论

暂无评论...
验证码 换一张
取 消