Search code examples
pythondjangodjango-registration

Removing second password input from django-registration form


I am using django-registration v1.0 for signups. By default, the signup page has 4 input fields:

  • username
  • email
  • password1
  • password2

The django-registration documentation justifies that the repeated entry of the password serves to catch typos. But I want to remove the second password field.

How do I do this?


Solution

  • This is how I got it working, in case it helps someone:

    In forms.py

    from registration.forms import RegistrationForm
    
    class UserRegistrationForm(RegistrationForm):
        def __init__(self, *args, **kwargs):
            super(RegistrationForm, self).__init__(*args, **kwargs)
            self.fields.pop('password2')
    

    In views.py

    from registration.backends.simple.views import RegistrationView
    from .forms import UserRegistrationForm
    
    class MyRegistrationView(RegistrationView):
        form_class= UserRegistrationForm
    

    In urls.py

    from links.views import MyRegistrationView
    
    url(r'^register/$', MyRegistrationView.as_view(), name='register'),
    

    Thanks to karthikr for the comments.