How to use another view to register django?

I am trying to get django-registration to use view RegistrationFormUniqueEmail and after resolving this issue django-registration . I set urls.py to

from django.conf.urls import patterns, include, url from registration.forms import RegistrationFormUniqueEmail from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), (r'^users/', include('registration.backends.default.urls')), url(r'^users/register/$', 'registration.backends.default.views.RegistrationView', {'form_class': RegistrationFormUniqueEmail, 'backend': 'registration.backends.default.DefaultBackend'}, name='registration_register'), ) 

However, I can still create multiple accounts with the same email address. What is the problem? Should django registration use the view I specified? I am currently using django-registration 0.9b1.

+4
source share
2 answers

The version of Django you entered has been rewritten to use class-based views. This means a different approach is required in your urls.py.

First, you need to subclass RegistrationView and set a custom form class.

 from registration.backends.default.views import RegistrationView from registration.forms import RegistrationFormUniqueEmail class RegistrationViewUniqueEmail(RegistrationView): form_class = RegistrationFormUniqueEmail 

Then use your subheading RegistrationViewUniqueEmail in your URLs. As with other classes, you should call as_view ().

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

Make sure your customized registration_register view appears before you enable the default registration URLs, otherwise it will not be used.

+17
source

Version 1.2 of django-registration-redux allows you to use unique email with the following urls.py templates:

 url(r'^accounts/register/$', RegistrationView.as_view(form_class=RegistrationFormUniqueEmail), name='registration_register'), url(r'^accounts/', include('registration.backends.default.urls')), 

If you need to do something more, such as a specific URL, you can subclass RegistrationView in your views.py and RegistrationForm applications in your forms.py application

+2
source

Source: https://habr.com/ru/post/1479182/


All Articles