bab bab - 1 year ago 155
Python Question

How to use different view for django-registration?

I have been trying to get django-registration to use the view RegistrationFormUniqueEmail and following the solution from this django-registration question. I have set my to

from django.conf.urls import patterns, include, url

from registration.forms import RegistrationFormUniqueEmail

from django.contrib import admin

urlpatterns = patterns('',
url(r'^admin/', include(,
(r'^users/', include('registration.backends.default.urls')),
url(r'^users/register/$', 'registration.backends.default.views.RegistrationView',
{'form_class': RegistrationFormUniqueEmail,
'backend': 'registration.backends.default.DefaultBackend'},

However, I can still create multiple accounts with the same email. What is the problem? Shouldn't django-registration be using the view that I specified? I am currently using django-registration 0.9b1.

Answer Source

The version of Django registration you are using has been rewritten to use class based views. This means a different approach is required in your

First, You need to subclass the RegistrationView, and set the custom form class.

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

class RegistrationViewUniqueEmail(RegistrationView):
    form_class = RegistrationFormUniqueEmail

Then, use your custom RegistrationViewUniqueEmail subclass in your urls. As with other class based views, you must call as_view().

url(r'^user/register/$', RegistrationViewUniqueEmail.as_view(),

Make sure your customised registration_register view comes before you include the default registration urls, otherwise it won't be used.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download