How to migrate this code for Django-registration to version 1.0 of the module?

*爱你&永不变心* 提交于 2019-12-25 16:58:04

问题


I have a Django application running an older version Django-Registration. In that application, I'm overriding the normal registration form with a custom one that I have created like so:

from myApp.forms import extendedRegistrationForm

# using my registration form to override the default
url (
    r'^accounts/register/$', 
    'registration.views.register',
    {
        'form_class': extendedRegistrationForm,
        'backend': 'registration.backends.default.DefaultBackend',
    }
),    

It works fine. However, I am now migrating to the current version of Django-registration which I'm told does not have a view named registration.views.register. Instead it has a class-based view RegistrationView. So I get the following error:

Could not import registration.views.register. View does not exist in module registration.views.

Can someone show me how to adapt my code above to work with RegistrationView?


回答1:


Try

from registration.views import RegistrationView

register = RegistrationView.as_view()

url (
    r'^accounts/register/$', 
    register,
    {
        'form_class': extendedRegistrationForm,
        'backend': 'registration.backends.default.DefaultBackend',
    }
),  


来源:https://stackoverflow.com/questions/20725400/how-to-migrate-this-code-for-django-registration-to-version-1-0-of-the-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!