How do I use the built in password reset/change views with my own templates How do I use the built in password reset/change views with my own templates python python

How do I use the built in password reset/change views with my own templates


If you take a look at the sources for django.contrib.auth.views.password_reset you'll see that it uses RequestContext. The upshot is, you can use Context Processors to modify the context which may allow you to inject the information that you need.

The b-list has a good introduction to context processors.

Edit (I seem to have been confused about what the actual question was):

You'll notice that password_reset takes a named parameter called template_name:

def password_reset(request, is_admin_site=False,             template_name='registration/password_reset_form.html',            email_template_name='registration/password_reset_email.html',            password_reset_form=PasswordResetForm,             token_generator=default_token_generator,            post_reset_redirect=None):

Check password_reset for more information.

... thus, with a urls.py like:

from django.conf.urls.defaults import *from django.contrib.auth.views import password_reseturlpatterns = patterns('',     (r'^/accounts/password/reset/$', password_reset, {'template_name': 'my_templates/password_reset.html'}),     ...)

django.contrib.auth.views.password_reset will be called for URLs matching '/accounts/password/reset' with the keyword argument template_name = 'my_templates/password_reset.html'.

Otherwise, you don't need to provide any context as the password_reset view takes care of itself. If you want to see what context you have available, you can trigger a TemplateSyntax error and look through the stack trace find the frame with a local variable named context. If you want to modify the context then what I said above about context processors is probably the way to go.

In summary: what do you need to do to use your own template? Provide a template_name keyword argument to the view when it is called. You can supply keyword arguments to views by including a dictionary as the third member of a URL pattern tuple.


You just need to wrap the existing functions and pass in the template you want. For example:

from django.contrib.auth.views import password_resetdef my_password_reset(request, template_name='path/to/my/template'):    return password_reset(request, template_name)

To see this just have a look at the function declartion of the built in views:

http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/views.py#L74