我怎样才能覆盖中的默认clean_email()
方法allauth.account.forms.BaseSignupForm
。我在 Forms.py 中尝试了以下内容:
from allauth.account.forms import BaseSignupForm
class Extended_BaseSignupForm(BaseSignupForm):
def clean_email(self):
data = self.cleaned_data['email']
if "@gmail.com" not in data: # any check you need
raise forms.ValidationError("Must be a gmail address")
if app_settings.UNIQUE_EMAIL:
if data and email_address_exists(data):
raise forms.ValidationError \
(_("A user is registered with this e-mail address."))
return data
覆盖的目的是防止用户使用一次性电子邮件 ID 进行注册。