django-allauth:模块"accounts.forms"没有定义"SignupForm"类

 愤然尔立_980 发布于 2023-02-08 09:26

我收到以下错误:

django.core.exceptions.ImproperlyConfigured:模块"accounts.forms"没有定义"SignupForm"类

settings.py

(...)

ACCOUNT_SIGNUP_FORM_CLASS = 'accounts.forms.SignupForm'

(...)

账户/ forms.py

from allauth.account.forms import BaseSignupForm

class SignupForm(BaseSignupForm):

    def __init__(self, *args, **kwargs):
        self.sociallogin = kwargs.pop('sociallogin')
        user = self.sociallogin.account.user
        first_name = forms.CharField(label=_('First name'),
                                     max_length=30,
                                     min_length=2,
                                     widget=forms.TextInput(attrs={
                                         'placeholder':_('First name')}))
        last_name = forms.CharField(label=_('Last name'),
                                     max_length=30,
                                     min_length=2,
                                     widget=forms.TextInput(attrs={
                                         'placeholder':_('Last name')}))
        second_last_name = forms.CharField(label=_('Second last name'),
                                     max_length=30,
                                     empty='',
                                     widget=forms.TextInput(attrs={
                                         'placeholder':_('Second last name')}))
        # TODO: Should become more generic, not listing
        # a few fixed properties.
        initial = {'email': user_email(user) or '',
                   'username': user_username(user) or '',
                   'first_name': user_field(user, 'first_name') or '',
                   'last_name': user_field(user, 'last_name') or ''}
        kwargs.update({
            'initial': initial,
            'email_required': kwargs.get('email_required',
                                         app_settings.EMAIL_REQUIRED)})
        super(SignupForm, self).__init__(*args, **kwargs)

    def save(self, request):
        adapter = get_adapter()
        user = adapter.save_user(request, self.sociallogin, form=self)
        # TODO: Add request?
        super(SignupForm, self).save(user)
        return user

    def raise_duplicate_email_error(self):
        raise forms.ValidationError(
            _("An account already exists with this e-mail address."
              " Please sign in to that account first, then connect"
              " your %s account.")
            % self.sociallogin.account.get_provider().name)

Aamir Adnan.. 18

先生,您是循环进口的受害者.allauth尝试从accounts.forms您从allauth导入的同一文件中导入您的自定义注册表单类from allauth.account.forms import BaseSignupForm.你不需要扩展你SignupFormBaseSignupForm.只需创建一个简单的表单,allauth就会自动为您扩展.

2 个回答
  • 只需继承forms.Form并添加注册功能即可。

    class CustomSignupForm(forms.Form):
        def signup(self, request, user):
            pass
    
    ACCOUNT_SIGNUP_FORM_CLASS = 'app.forms.CustomSignupForm'
    

    2023-02-08 09:28 回答
  • 先生,您是循环进口的受害者.allauth尝试从accounts.forms您从allauth导入的同一文件中导入您的自定义注册表单类from allauth.account.forms import BaseSignupForm.你不需要扩展你SignupFormBaseSignupForm.只需创建一个简单的表单,allauth就会自动为您扩展.

    2023-02-08 09:28 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有