I have a URL handler for changing passwords, such as this:
url(r'^password/change/$',
auth_views.password_change,
{'template_name' : 'account/password/password_change_form.html'},
name='auth_password_change'),
All is good, and my template is loaded, and password changing works as expected. However, my template needs to access request.user. The request object is not passed by default to the template from the built-in the auth_views.password_change view.
I know that the auth_views.password_change view can be passed in extra context, which it will pass along to the template. I just do not know how to do it in my URL handler.
I know that I could just write another view which wraps around auth_views.password_change, but I am curious if there is a shortcut way to do it from within the URL handler.
Can you show me how to modify my current URL handler to pass in the current request object as extra_context to the auth_views.password_change view?
Normally you do that in the urlconf – but you can’t pass
request.userin extra_context, because the urls.py has no access to the request.But
password_change, like all built-in views, usesRequestContextto render the template – which means that there is auserobject there automatically (passed in bydjango.contrib.auth.context_processors.auth, unless you’ve removed it from theCONTEXT_PROCESSORSlist in settings.py).