Django-allauth: Custom SignUp Form has no longer Password1 and Password2 fields

Created on 10 Apr 2017  路  4Comments  路  Source: pennersr/django-allauth

We upgraded to allauth 0.31.0 and now we have the problem that our custom signup form doesn't work anymore.
We specified a custom field_order like this:

class SignupForm(forms.Form):
def __init__(self, args, *kwargs):
super(SignupForm, self).__init__(args, *kwargs)
if hasattr(self, 'sociallogin'):
fields_keyOrder = ['username', 'email', 'timezone', 'tos_agreed']
else:
fields_keyOrder = ['username', 'email', 'password1', 'password2', 'timezone', 'captcha', 'tos_agreed']
if (self.fields.has_key('keyOrder')):
self.fields.keyOrder = fields_keyOrder
else:
self.fields = OrderedDict((k, self.fields[k]) for k in fields_keyOrder)

But now we get a key error for password1 and password2. I looked at self.fields (after calling super) and it has all fields, except password fields anymore. If I remove password1 and password2 the form can be rendered but of course the password fields come last (at the bottom of the form). Any ideas what was changed? I am very sure it worked with 0.28 before

Most helpful comment

ACCOUNT_SIGNUP_FORM_CLASS should not inherit from SignupForm. This form should only contain additional fields that are to be included into the bigger SignupForm class. So:

  • Do you want to ask the user for his favorite color during signup? Create a form inheriting from forms.Form, add just this one field (color), and point ACCOUNT_SIGNUP_FORM_CLASS to it.

  • Do you want to alter the behavior of the overall signup form (including altering field order and so on)? Use ACCOUNT_FORMS.

All 4 comments

The custom signup form only contains the additional fields, not the username/email/password fields. If you need to change the field order, you should override the real signup form which has all the fields, not the custom one. See ACCOUNT_FORMS for that.

I can not get it to work. It worked for nearly two years and after upgrading allauth our code broke. We have followed your advise from Issue 826 where you explained how to build a custom signup form.
https://github.com/pennersr/django-allauth/issues/826
No matter what I try, I can not get our Code to work again. This is driving me crazy. I want to inherit from allauth.account.forms.SignupForm but not matter what I do, either Python / Django can not find it, or settings.py complains that it can not find my custom ACCOUNT_SIGNUP_FORM_CLASS.
So between 0.28 (we started with 0.15 I think or even earlier) and 0.31 you must have changed something broke the code and rendered your solution from February 2015 useless. :(

I just downgraded to 0.28.0 and now it works again. Your ChangeLog doesn't state anything out of the ordinary.
Then I started to upgrade step by step, I can confirm that 0.30.0 still works but 0.31.0 breaks the code.

ACCOUNT_SIGNUP_FORM_CLASS should not inherit from SignupForm. This form should only contain additional fields that are to be included into the bigger SignupForm class. So:

  • Do you want to ask the user for his favorite color during signup? Create a form inheriting from forms.Form, add just this one field (color), and point ACCOUNT_SIGNUP_FORM_CLASS to it.

  • Do you want to alter the behavior of the overall signup form (including altering field order and so on)? Use ACCOUNT_FORMS.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

slimaidarismail picture slimaidarismail  路  3Comments

FSE-DEV picture FSE-DEV  路  5Comments

psychok7 picture psychok7  路  5Comments

gitdeepak picture gitdeepak  路  5Comments

peterhn picture peterhn  路  4Comments