我正在按照tutorial.
的方式使用django-widget-tweaks创建表单视图
当我尝试实现add_class过滤器时,出现以下错误。
无效的过滤器:'add_class'
有人知道如何解决此错误吗?
html页面
{% extends "base.html" %}
(% load widget_tweaks %}
{% block content %}
<form method="post" enctype="multipart/form-data">
<h4 style="margin-top: 0">Project Upload</h4>
{% csrf_token %}
{% for hidden in form.hidden_fields %}
{{hidden}}
{% endfor %}
{% for field in form.visible_fields %}
<div class="form-group">
<label for="{{field.id_for_label}}">{{field.label}}</label>
{{field|add_class:"form-control"}}
</div>
{% endfor %}
<button type="submit">Upload</button>
</form>
{% endblock %}
form.py
class DocumentForm(forms.ModelForm):
class Meta:
model=html
fields=['project','version','diff','program','location']
答案 0 :(得分:0)
您可以查看此here
{% load widget_tweaks %}
<!-- add 2 extra css classes to field element -->
{{ form.title|add_class:"css_class_1 css_class_2" }}
答案 1 :(得分:0)
尝试一下:
{% render_field field|add_class:"form-group"%}