Sinidex
Sinidex

Reputation: 503

How do I check a field name from a Django form in html?

I have a Django form that contains several fields I am looping through. I want to branch the code if the field is the "comment" field, something like this:

{% for field in form.visible_fields %}
    {% if field == form.fields.comment %}
        <do something>
    {% else %}
        <do something else>
    {% endif %}
{% endfor %}

What is the correct syntax for the 2nd line? The current line always fails.

Upvotes: 1

Views: 133

Answers (1)

Skylar Saveland
Skylar Saveland

Reputation: 11454

I believe it would be:

{% if field.field == form.fields.comment %}

Upvotes: 5

Related Questions