Python 在Django allauth中重写clean_email()方法

Python 在Django allauth中重写clean_email()方法,python,django,django-forms,django-allauth,Python,Django,Django Forms,Django Allauth,如何覆盖allauth.account.forms.BaseSignupForm中的默认clean_email()方法。 我在Forms.py中尝试了以下操作: from allauth.account.forms import BaseSignupForm class Extended_BaseSignupForm(BaseSignupForm): def clean_email(self): data = self.cleaned_data[

如何覆盖
allauth.account.forms.BaseSignupForm
中的默认
clean_email()
方法。 我在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注册。

基本上,您需要重写URL以将表单类传递给view as关键字参数


这在即将发布的allauth版本中变得更容易了。您只需覆盖
clean_email
adapter方法,如下所示:


使用
ACCOUNT\u ADAPTER
设置指向包含覆盖方法的自定义适配器

你应该粘贴完整的URL.py。谢谢你提供的信息,我想现在更新是唯一的解决办法。@pennersr:allauth太棒了。我遵循同样的逻辑,用我的正则表达式覆盖
clean_username
。然而,我认为,这些更改必须在另外两个地方复制,即
\u generate\u unique\u username\u base
(在allauth中)和
UserChangeForm
(在django中)。对吗?