[英]Get form field class in template
我想检查我的模板中是否有任何表单字段在其类中具有某些值。
例如:
*我的表单字段:
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 %}
有什么办法可以做到这一点?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.