Reputation: 2678
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)
Upvotes: 8
Views: 2702
Reputation: 1919
I had this issue but it was not happening from the SignupForm class, (I referenced it correctly as @aamir suggested).
Instead, it was because I had LoginForm subclassed in the same file as the SignupForm class. For whatever reason, this was also causing a circular import. It also was only happening when I imported views while writing tests, not sure why.
I found this solution, which was to just give SignupForm its own forms.py file to live in and it fixed this issue.
Upvotes: 0
Reputation: 1448
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'
Upvotes: 6
Reputation: 39689
Sir you are victim of Circular Import. allauth tries to import your custom signup form class from accounts.forms
but in the same file you are importing from allauth from allauth.account.forms import BaseSignupForm
. You don't need to extend your SignupForm
from BaseSignupForm
. Just create a simple form and allauth will automatically extend it for you.
Upvotes: 22
Reputation: 2693
Try importing SignupForm instead of BaseSignupForm from django-allauth.
Upvotes: -1