在模板中获取表单字段类

我想检查我的模板中是否有任何表单字段在其类中具有某些值。

EG:

*我的表单字段:

alcohol_percentage = DecimalField(max_digits=4,decimal_places=2,required=False,label='Alcohol',widget=(NumberInput(attrs={'class': 'form-control percentage'})))

*然后在我的模板中:

{% for field in form %}
    {{ field.label }}
    {{ field }}
    {% if 'percentage' in field.widget %}
    <!-- doing something -->
    {% endif %}
{% endfor %}

有什么方法可以实现?

ying_09222 回答:在模板中获取表单字段类

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3044211.html

大家都在问