0

I have customize Django 1.5 (from djangoproject docs) authentication to login with email instead of username and its working perfect, but I am using Django-registration 1.0 to register users.

How do I remove the username field from django registration so users will only need to enter e-mail & password when registering.

Thank you all in advance. Yaniv M

yaniv14
  • 691
  • 1
  • 10
  • 24

3 Answers3

2

This should get you started. Create your own form that is a subclass of RegistrationForm.

In forms.py

from registration.forms import RegistrationForm

class MyRegistrationForm(RegistrationForm):

    # Override RegistrationForm
    def __init__(self, *args, **kwargs):
        super(RegistrationForm, self).__init__(*args, **kwargs)
        self.fields.pop('username')

In views.py

from registration.views import RegistrationView

from yourapp.forms import MyRegistrationForm


class MyRegistrationView(RegistrationView):
    form_class = MyRegistrationForm

In urls.py

url(r'^accounts/register/$', MyRegistrationView.as_view(),
    name='registration'),
xiao
  • 1,718
  • 4
  • 23
  • 31
0

You can create a custom form class based on default RegistrationForm and use that class in the RegistrationView view.

maulik13
  • 3,656
  • 1
  • 25
  • 36
  • With a custom form class will I'll be able to remove the requirement of username field? or just add custom fields to the registration form? – yaniv14 Jun 22 '13 at 13:49
  • In the custom class you can remove username field entirely or make it optional. – maulik13 Jun 22 '13 at 15:29
0

As-is, it's complicated. You need to:

  • apply this patch because in d-r-1.0, models.py assumes your User model has a "username" field
  • create your own "backend" by copy/pasting/editing registration/backends/default/views.py
  • copy/paste/edit the registration form as well from registration/forms.py
  • most of the time you can use the registration views without modification
orzel
  • 322
  • 2
  • 7