问题
I'm migrating from an older version of Django-Registration to the 1.0 version of the module.
I'm overriding the normal registration form with a custom one that I have created. This behavior has stopped working with Django-registration 1.0 and I'm trying to get it working again. But have not been successful so far. This is what my urls.py file looks like:
from registration.views import RegistrationView
from myApp.forms import *
<...SNIPPED...>
url (
r'^accounts/register/$',
RegistrationView.as_view(),
{
'form_class': extendedRegistrationForm,
'backend': 'registration.backends.default.DefaultBackend',
}
)
This is what myApp's forms.py looks like:
from registration.forms import RegistrationFormUniqueEmail
<...SNIPPED...>
class extendedRegistrationForm(RegistrationFormUniqueEmail):
firstName = forms.CharField(
widget=forms.TextInput(),
label="First Name",
required=False,
)
The behavior I am seeing is this: On the registration screen, their are input boxes and field labels for Username, Email address, Password, Password Confirm. However, the slot in my form where the input box and field label for "First Name" should appear are completely empty.
How to modify the urls.py and forms.py so that the fields in my extendedRegistrationForm get properly included on the screen? Almost the identical code was working fine with the older version Django-Registration.
回答1:
Firstly, import the view from the default backend module if you want to use the default backend.
from registration.backends.default.views import RegistrationView
Secondly, you can set the form_class
by subclassing RegistrationView
, or by passing it as an argument to as_view()
. See the CBV docs for further information.
url (
r'^accounts/register/$',
RegistrationView.as_view(form_class=extendedRegistrationForm),
)
来源:https://stackoverflow.com/questions/20738954/how-to-over-ride-default-registration-form-in-django-registration-version-1-0