I've just switched to using django-registration to manage user authentication on my website. Before, I used views for the register and login pages, and so was able to specify context parameters. But now, I no longer have views for these pages, as django-registration takes care of this for me. I still need to pass the context variables though, so I've tried this:
urls.py:
import registration
from registration.backends.default.views import RegistrationView
...
(r'^accounts/login/$', 'django.contrib.auth.views.login', { 'extra_context' : {'design_form': True }}),
(r'^accounts/register/$', RegistrationView.as_view(form_class=RegistrationForm), { 'extra_context' : {'design_form': True }}),
(r'^accounts/', include('registration.backends.default.urls')),
The 'design_form' parameter functions correctly on the accounts/login/ page but does not get passed to the registration page. How do I pass extra_context to my registration page?
Using django 1.5 and django-registration 1.0
As RegistrationForm is descendant of django.views.generic.FormView
and in turn of django.generic.views.View
, passing extra_content
is done by overriding get_context_data
, example included.
Function-based generic views provided an
extra_context
argument as way to insert extra items into the context at time of rendering.Class-based views don't provide an extra_context argument. Instead, you subclass the view, overriding
get_context_data()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.