How to over-ride default registration form in Django-Registration version 1.0?

杀马特。学长 韩版系。学妹 提交于 2019-12-11 05:46:11

问题


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

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