Posts tagged newforms
If you want to mark required fields with * or some other text/symbol - don’t use some hacks in your python code (Label modify in form class, etc.). Things like that should reside in templates and all you need to do is to apply this:
{% if field.field.required %} <em>*</em>{% endif %}
E.g. form display template:
<form action="." method="post">
{% csrf_token %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
<dl>
{% for field in form.visible_fields %}
{% if field.errors %}
<dt> </dt>
<dd>{{ field.errors }}</dd>
{% endif %}
<dt>
{{ field.label_tag }}
{% if field.field.required %} <em>*</em>{% endif %}:
</dt>
<dd>{{ field|safe }}</dd>
{% endfor %}
<dt> </dt>
<dd><input type="submit" value="Submit" /></dd>
</dl>
</form>

