Reputation: 1042
How can I arrange my form in a table?
I had a normal form and I was arranging it in my template like this.
<table border="0" >
{% for field in form %}
<tr >
<td>
<label for="{{ field.label }}">{{ field.label_tag }}
{% if field.field.required %}<span style="color:red"; class="special_class">*</span>{% endif %}</label>
</td>
<td>
{{ field }}
</td>
</tr>
{% endfor %}
</table>
Now I want to use crispy forms. but couldn't figure out how to display my form.
of cause it has works with this.
{% load crispy_forms_tags %}
{% crispy form %}
but that was not arranging my fields well,
how can I access these fields by a loop? Any help would be greatly appreciated.
Upvotes: 1
Views: 1424
Reputation: 156
You can iterate over fields and then use crispy like this:
{% for field in form %}
{{ field|as_crispy_field }}
{% endfor %}
Upvotes: 9