Django-registration, force unique e-mail

前端 未结 7 1459
遇见更好的自我
遇见更好的自我 2020-12-03 14:32

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

相关标签:
7条回答
  • 2020-12-03 14:43

    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 ]

    0 讨论(0)
  • 2020-12-03 14:45

    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'))
    
    ]
    
    0 讨论(0)
  • 2020-12-03 14:49

    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

    0 讨论(0)
  • 2020-12-03 14:53

    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.

    0 讨论(0)
  • 2020-12-03 14:57

    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'),
    )
    
    0 讨论(0)
  • 2020-12-03 15:01

    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'),
    
    0 讨论(0)
提交回复
热议问题