Django: How do I use a different form_class with django-registration

China☆狼群 提交于 2019-12-14 03:44:49

问题


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

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

回答1:


Looking at the views.register function,

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

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



来源:https://stackoverflow.com/questions/3205288/django-how-do-i-use-a-different-form-class-with-django-registration

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