Customizing Django Form: Required and InputId?
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-02-13T05:58:45Z
Indexed on
2010/03/15
10:19 UTC
Read the original article
Hit count: 177
django-forms
I'm trying to customize how my form is displayed by using a form_snippet as suggested in the docs. Here's what I've come up with so far:
{% for field in form %}
<tr>
<th><label for="{{ field.html_name }}">{{ field.label }}:</label></th>
<td>
{{ field }}
{% if field.help_text %}<br/><small class="help_text">{{ field.help_text }}</small>{% endif %}
{{ field.errors }}
</td>
</tr>
{% endfor %}
Of course, field.html_name
is not what I'm looking for. I need the id
of the input field. How can I get that?
Also, is there a way I can determine if the field is required, so that I can display an asterisk beside the label?
© Stack Overflow or respective owner