【问题标题】:Custom Form with Socialaccount in Django-allauth在 Django-allauth 中使用 Socialaccount 自定义表单
【发布时间】:2019-07-29 12:50:38
【问题描述】:

我正在尝试使用 django-allauth 修改社交帐户(在我的情况下使用 Google)注册。

我想要实现的是让用户点击我的“使用 Google 注册”按钮,但在 Google 登录后(在回调中)我想向用户展示一份同意书(关于规则/GDPR ) 他需要在完成程序之前提交。

这是我的表格:

// landing/forms.py
from allauth.socialaccount.forms import SignupForm

class GoogleSignUpForm(SignupForm):
    privacy_policy = forms.BooleanField(
        required=True,
        label=_('I accept the privacy policy and rules '),
        help_text=_('You need to accept this to proceed with setting-up your account')
    )



    def __init__(self, sociallogin=None, **kwargs):
        super(GoogleSignUpForm, self).__init__(**kwargs)
        terms_and_conditions = reverse_lazy('privacy')
        self.fields['privacy_policy'].label = mark_safe(_(
            "I have read and agree with the "
            "<a href='%s'>Terms and Conditions</a>")) % (
                                                  terms_and_conditions)

    def save(self):
        user = super(GoogleSignUpForm, self).save()
        return user

我的 base.py 设置文件中有以下设置:

SOCIALACCOUNT_FORMS = {'signup': 'landing.forms.GoogleSignUpForm'}

然而 - 导入行 from allauth.socialaccount.forms import SignupForm 给了我以下错误:

django.core.exceptions.ImproperlyConfigured: Error importing form class landing.forms: "cannot import name 'BaseSignupForm'"

为什么会发生这种情况以及如何使其发挥作用?

【问题讨论】:

  • 您找到解决方案了吗?我也面临同样的问题。

标签: django django-forms django-allauth


【解决方案1】:

在我们的例子中,这是由自定义 ACCOUNT_SIGNUP_FORM_CLASS 引起的。使用默认类并且只设置ACCOUNT_FORMS 解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    • 2014-08-11
    • 1970-01-01
    相关资源
    最近更新 更多