开发者

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

开发者 https://www.devze.com 2023-02-27 23:38 出处:网络
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:

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 i开发者_运维知识库s the correct syntax for the 2nd line? The current line always fails.


I believe it would be:

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

精彩评论

暂无评论...
验证码 换一张
取 消