我想在我的自定义SignupForm(设置为help_text
中的password1
字段中设置ACCOUNT_SIGNUP_FORM_CLASS = 'myapp.forms.SignupForm'
。
否则该表单可以正常工作,但是我不能修改password1
字段,因为它是Allauth从 my SignupForm继承时创建的。
我的SignupForm
,在其中添加了一个复选框并调整了一些简单的操作:
class SignupForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class Meta:
model = Client
fields = [
'phone_number',
'pin',
'address',
'zipcode',
'city',
]
widgets = {
'phone_number': phone_number_widget,
}
agree_to_terms = forms.BooleanField(
label=mark_safe(
ugettext('I agree to the <a href="/terms">terms and conditions</a>')
)
)
field_order = ['name'] + Meta.fields + [
'email', 'password1', 'password2', 'agree_to_terms'
]
在Allauths的account/forms.py
中:
class SignupForm(BaseSignupForm):
def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__(*args, **kwargs)
self.fields['password1'] = PasswordField(label=_("Password"))
if app_settings.SIGNUP_PASSWORD_ENTER_TWICE:
self.fields['password2'] = PasswordField(
label=_("Password (again)"))
...
...
有没有办法解决这个问题?
答案 0 :(得分:0)
您的SignupForm
应该是allauth SignupForm
的子类,这样它将从BaseSignupForm
继承,而不是BaseSignupForm
从您的表单继承:
from allauth.account.forms import SignupForm as AllauthSignupForm
class SignupForm(ModelForm, AllauthSignupForm):
...
然后在设置中设置ACCOUNT_FORMS = {'signup': 'my_app.forms.SignupForm'}
。