[Answered ]-Django-allauth and custom Signup form

2👍

After a few days off, I returned and found the silly mistake!

In my Form.py the password field is called ‘password1’ not password!

class SignupForm(forms.Form):
    first_name = forms.CharField(max_length=30)
    last_name = forms.CharField(max_length=30)

def __init__(self, *args, **kwargs):
  super(SignupForm, self).__init__( *args, **kwargs)
  self.helper = FormHelper()
  self.helper.form_show_labels = False
  self.helper.field_class = ''
  self.helper.layout = Layout(
    Field('first_name', placeholder='First Name', autocomplete='off'),
    Field('last_name', placeholder='Last Name', autocomplete='off'),
    Field('email', placeholder='Email', autocomplete='off'),
    Field('password1', placeholder='Password', autocomplete='off'),

    Div(Submit('Register', 'Register', css_class='btn btn-primary block full-width m-b'), css_class='form-group'),
    HTML('<p class="text-muted text-center"><small>Already have an account?</small></p>'),
    Div(HTML('<a class ="btn btn-sm btn-white btn-block" href="' + reverse('account_login') + ' " > Login </a>'),css_class='form-group' )
)

def signup(self, request, user):
    user.first_name = self.cleaned_data['first_name']
    user.last_name = self.cleaned_data['last_name']
    user.save()

Great days!

👤MWit

Leave a comment