Django-registration, force unique e-mail

Posted on

Question :

Django-registration, force unique e-mail

Can I force users to make unique e-mail addresses in django-registration?

Asked By: DJPython

||

Answer #1:

For later versions of django_registration (that use class-based views), you can do this:

from registration.forms import RegistrationFormUniqueEmail
from registration.backends.default.views import RegistrationView

urlpatterns = patterns('',
    url(r'^register/$',
        RegistrationView.as_view(form_class=RegistrationFormUniqueEmail),
        name='registration_register'),
)
Answered By: seddonym

Answer #2:

from rych’s answer, I tested that the following runs ok – it only uses urls.py, you needn’t write another cusotmer form.

from registration.forms import RegistrationFormUniqueEmail

url(r'^accounts/register/$', 'registration.views.register',
    {'form_class': RegistrationFormUniqueEmail,
     'backend': 'registration.backends.default.DefaultBackend'},       
     name='registration_register'),
Answered By: raidsan

Answer #3:

django-registration has several forms included in the source – one is a RegistrationFormUniqueEmail, which might help you …


P.S. You can adjust the form to use by changing the default backend or by implementing a custom one, where you return the appropriate form class, see: http://bitbucket.org/ubernostrum/django-registration/src/073835a4269f/registration/backends/default/init.py#cl-118

Answered By: miku

Answer #4:

forms.py

from registration.forms import RegistrationFormUniqueEmail

class RegistroPerfilForm(RegistrationFormUniqueEmail):
    first_name= forms.CharField(required=True)
    last_name= forms.CharField(required=True)
    kind__of_user= forms.CharField(widget=forms.RadioSelect(choices=TIPO))
Answered By: Asinox

Answer #5:

As miku pointed out, you should simply use RegistrationFormUniqueEmail .

If you implement according to the documentation and bug report replies (as of mid-2011),
you’ll probably end up with an exception like:

TypeError at /accounts/register/
register() takes at least 2 non-keyword arguments (1 given)

your urlconf should look like this to properly specify this backend:

(r'^accounts/register/', 'registration.views.register' {'form_class':RegistrationFormUniqueEmail, 'backend':'registration.backends.default.DefaultBackend' }),
(r'^accounts/', include('registration.backends.default.urls')),

[ please excuse the additional answer, as this belongs as a comment to miku’s correct answer; I don’t have the privilege of commenting, but this tip may save at least a few people 15 minutes each, so is hopefully worth the forced faux-pas ]

Answered By: rych

Answer #6:

It should suffice to create your registration form from your user model. If the e-mail address is defined to be unique there, the form will output an error on submit for duplicate addresses.

Look here for details.

As Dominic points out, you’ll not be able to do this with the built-in user profile. You’ll have to extend it by creating your own user profile as described here and make it contain a unique e-mail address.

Answered By: Johannes Charra

Answer #7:

For unique e-mail addresses in django-registration-redux 1.4.

In url.py add following

from registration.forms import RegistrationFormUniqueEmail

from registration.backends.default.views import RegistrationView

urlpatterns = [
 url(r'^accounts/register/$',RegistrationView.as_view(form_class=RegistrationFormUniqueEmail),
        name='registration_register'),

 url(r'^accounts/', include('registration.backends.default.urls'))

]
Answered By: Deep 3015

Leave a Reply

Your email address will not be published. Required fields are marked *