I've got a modelform that I would like to iterate through the form fields in the template but at the same time, when I encounter certain fields, to conditionally render extra html. Currently I am pulling the field name from field.html_name
but I am not sure if that is the best way (it feels hackish somehow, like I should be using a getattr()
filter or something...).
{% for field in form %}
<div class="form-group">
{{ field }}
{% if field.html_name == "location" %}
<!-- CUSTOM HTML HERE -->
{% endif %}
</div>
{% endfor %}