[Django]-Tell if a Django Field is required from template

122πŸ‘

βœ…

{% if field.field.required %}

From this snippet

2πŸ‘

I usually write out the html for each of my form elements, so I have a little more control over each one. Then you can add an * for required or REQUIRED!!.

<p><label>Title: *<br />
{% if form.title.errors %}<ul class="errorlist">{{ form.title.errors }}</ul>{% endif %}
{{form.title}}
</label></p>    

<p><label>Category:<br />
{% if form.category.errors %}<ul class="errorlist">{{ form.category.errors }}</ul>{% endif %}
{{form.category}}
</label></p>
πŸ‘€Joe

Leave a comment