我试图使用这个问题的第二个答案:CSS styling in Django forms
我正在尝试将类添加到输入中,这样我就可以设置表单的样式。使用自定义过滤器对我来说似乎是合理的。问题是,当我运行服务器时,我得到一个错误:addclass需要2个参数,1个提供了
这是我的代码:
myfilters.py:
from django import template
register = template.Library()
@register.filter(name='addclass')
def addclass(value, arg):
return value.as_widget(attrs={'class': arg})
contact.html:
<form method="post">
{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.nome_completo.errors }}
{{ form.nome_completo.label_tag }}
{{ form.nome_completo | addclass: 'form_nome-completo' }}
<span class="helptext">{{ form.nome_completo.help_text }}</span>
</div>
</form>
谢谢
目前没有回答
相关问题 更多 >
编程相关推荐