forms.py
my_field = TextField(u"Enter a number", validators=[Required('This Field is Required')])
my_form.html
<table>
<tr>
<td colspan="4">
{{form.my_field(placeholder= form.my_field.label.text, class_="form-control")}}
{% for error in form.my_field.errors %}
<span>{{error}}</span>
{% endfor %}
</td>
</tr>
</table>
This is a simple code. But I want to follow kind of this to render all the input fields in a loop instead of writing the code for each of them. But each field will have a different colspan
value in the corresponding <td>
.
How can I add a custom parameter for colspan which I can use in the <td>
?
Something like: (just the diff
from above code)
forms.py
my_field = TextField(colspan="4")
my_form.html
<td colspan={{form.my_field.colspan}}>