1 2 3 4 5 6 7 8 9 | {% for field in form %}
<div>
<label for="{{ field.label }}">{{ field.label_tag }}
{% if field.field.required %}<span class="special_class">*</span>{% endif %}</label>
{{ field }}
</div>
{% endfor %}
|
More like this
- Rendering a form by looping through its fields in a template by simon 4 years, 9 months ago
- Error rate limiter by s29 2 years, 7 months ago
- Run model validation before saving a model instance by buriy 2 years, 5 months ago
- South introspection rules for TimeZoneFields by serkan 2 years, 3 months ago
- CSRF this! by oggy 4 years, 8 months ago
Comments
It should be
<label for="{{ field.auto_id }}">(the id generated in the input,select and texarea fields)
#
Would be nice to see the snippet for this as a custom template tag
#
One may instead wrap the label text in a span with class="required", allowing an asterisk to be added via CSS:
This provides a useful hook for additional styling as well. For example, one might do the following:
This will further differential required from non-required fields.
#
The code should look more like this:
Combine with davidchambers styles for effect.
#