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 3 years, 4 months ago
- South introspection rules for TimeZoneFields by serkan 10 months, 4 weeks ago
- Get current user without a request object by t_rybik 1 year, 5 months ago
- Trigger a user password change by jedie 4 years, 5 months ago
- login on activation with django-registration by morgan 1 year, 11 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.
#