django_widget_tweaks
要循环窗体字段,请执行以下操作:
{% for field in form.visible_fields %}
<div class="form-group">
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
{% if form.is_bound %}
{% if field.errors %}
{% render_field field class="form-control is-invalid" %}
{% for error in field.errors %}
<div class="invalid-feedback">
{{ error }}
</div>
{% endfor %}
{% else %}
{% render_field field class="form-control is-valid" %}
{% endif %}
{% else %}
{% render_field field class="form-control" %}
{% endif %}
{% if field.help_text %}
<small class="form-text text-muted">{{ field.help_text }}</small>
{% endif %}
</div>
{% endfor %}
这将显示一个与Bootstrap4兼容的界面,除非显示如下字段
radio
当我需要使用
custom-control
form-control
上课。
如何过滤表单字段循环以排除无线电输入,以便可以单独编写此代码?
我需要了解如何过滤字段循环,以及如何正确处理字段类型
收音机