如何覆盖Django-Registration版本1.0中的默认注册表单? [英] How to over-ride default registration form in Django-Registration version 1.0?

查看:42
本文介绍了如何覆盖Django-Registration版本1.0中的默认注册表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从旧版本的Django-Registration迁移到模块的1.0版本.

I'm migrating from an older version of Django-Registration to the 1.0 version of the module.

我用我创建的自定义表格覆盖了普通注册表格.此行为已停止使用Django-registration 1.0,并且我正尝试使其再次正常工作.但是到目前为止还没有成功.这是我的urls.py文件的样子:

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',
    }
)

这是myApp的form.py的样子:

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.

如何修改urls.py和forms.py,以便我的ExtendedRegistrationForm中的字段正确显示在屏幕上?几乎相同的代码在旧版本的Django-Registration上也能正常工作.

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.

推荐答案

首先,如果要使用默认后端,请从默认后端模块导入视图.

Firstly, import the view from the default backend module if you want to use the default backend.

from registration.backends.default.views import RegistrationView

第二,您可以通过子类化 RegistrationView 或将其作为参数传递给 as_view()来设置 form_class .请参见 CBV文档获取更多信息.

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),
)

这篇关于如何覆盖Django-Registration版本1.0中的默认注册表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆