Django:如何使用不同的form_class与django注册 [英] Django: How do I use a different form_class with django-registration

查看:296
本文介绍了Django:如何使用不同的form_class与django注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望 django-registration(0.8版)使用我的自定义窗体而不是默认窗体。但是,我想继续使用默认的django注册视图。下面的其他部分应该如何实现?

I want django-registration (version 0.8) to use my custom form rather than the default one. However, I want to continue to use the default django-registration view. What should the rest of the line below look like to achieve this?

(r'^accounts/register'...),

我已经尝试过下面的一个语法错误:

I've tried this below but get a syntax error:

(r'^accounts/register/$', 
         'registration.views.register', 
         {'form_class': 'MyRegistrationForm'}, name='registration_register'),

当我尝试下面这个我得到注册( )至少需要2个非关键字参数(1个)

And when I try this one below I get register() takes at least 2 non-keyword arguments (1 given)

(r'^accounts/register/$',      
    'registration.views.register',             
    {'form_class':'MyRegistrationForm'}),


推荐答案

查看 views.register 函数,

def register(request, backend, success_url=None, form_class=None,
             disallowed_url='registration_disallowed',
             template_name='registration/registration_form.html',
             extra_context=None):

看到后端是必需的参数。尝试以下操作:

you can see that backend is a required argument. Try the following:

url(r'^accounts/register/$', 
         'registration.views.register', 
         {'form_class': MyRegistrationForm,
          'backend':'registration.backends.default.DefaultBackend'},
         name='registration_register'),

请注意,您需要使用 url(r'^ ...)如果你想命名你的网址。

note that you need to use url(r'^...) if you wish to name your url.

这篇关于Django:如何使用不同的form_class与django注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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