将error_css_class添加到SignupForm

时间:2018-07-28 21:52:29

标签: python django django-allauth

我正在使用Django Allauth SignupForm。它工作正常,但是当我向其中添加error_css_class='error'时,如果该字段无效,则不会添加class='error'。我该怎么做,以便在出现错误时像在forms.Forms中一样添加类名?

class RegisterForm(SignupForm):
    field_order = ['username', 'email', 'password']
    error_css_class = 'error'

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields['email'].label = "Email"

        self.fields['username'].widget = forms.TextInput(attrs={"placeholder": ""})
        self.fields['email'].widget = forms.EmailInput(attrs={"placeholder": ""})
        self.fields['password1'].widget = forms.PasswordInput(attrs={"placeholder": ""})

0 个答案:

没有答案