问题
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