Django: How do I use a different form_class with django-registration
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'}),
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.
精彩评论