django-allauth:模块“accounts.forms”没有定义“注册表”类 [英] django-allauth: Module "accounts.forms" does not define a "SignupForm" class

查看:185
本文介绍了django-allauth:模块“accounts.forms”没有定义“注册表”类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:


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


settings.py

 (...)

ACCOUNT_SIGNUP_FORM_CLASS ='accounts.forms.SignupForm'

(...)

accounts / forms.py


$来自allauth.account.forms导入的
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $


$ b def __init __(self, * args,** kwargs):
self.sociallogin = kwargs.pop('sociallogin')
user = self.sociallogin.account.user
first_name = forms.CharField(label = _ ('名字'),
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 =
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:应该变得更通用,没有列出
#几个固定的属性。
initial = {'email':user_email(user)or'',
'username':user_username(user)or'',
'first_name':user_field(user,'first_name' )或'',
'last_name':user_field(user,'last_name')或''}
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:添加请求?
super(SignupForm,self).save(user)
return user

def raise_duplicate_email_error(self):
raise forms.ValidationError(
_ 这个电子邮件地址已经存在。
请先登录该帐户,然后连接
您的%s帐户。)
%self.sociallogin。 account.get_provider()。name)


解决方案

只是继承自 forms.Form 并添加注册功能。

  class CustomSignupForm 
def signup(self,request,user):
pass

ACCOUNT_SIGNUP_FORM_CLASS ='app.forms.CustomSignupForm'


I am getting the following error:

django.core.exceptions.ImproperlyConfigured: Module "accounts.forms" does not define a "SignupForm" class

settings.py

(...)

ACCOUNT_SIGNUP_FORM_CLASS = 'accounts.forms.SignupForm'

(...)

accounts/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)

解决方案

Just inherit from forms.Form and add the signup function.

class CustomSignupForm(forms.Form):
    def signup(self, request, user):
        pass

ACCOUNT_SIGNUP_FORM_CLASS = 'app.forms.CustomSignupForm'

这篇关于django-allauth:模块“accounts.forms”没有定义“注册表”类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆