Question

I'm still new to Django and have a few questions on how using built in views work. I noticed that djang comes with a built in password change view at django.contrib.auth.views.password_change. This view shows the admin site in the background of the template, while I want to provide my own css/template but keep the form and functionality of that view. How would I do this? Can you pass something into the urls.py

r'password_change/$', 'django.contrib.auth.views.password_change')

like a custom template? I am unsure of the proper way to do this.

Was it helpful?

Solution

You can specify the template that should be used by setting the template_name argument:

(r'password_change/$', 'django.contrib.auth.views.password_change', {'template_name': 'path/to/password_reset.html'})

In your template make sure you use the provided {{ form }} template variable and you're good to go.

OTHER TIPS

Django will attempt to load templates first from your application, then fall back. So, to override the templates for contrib.auth, you just need to:

  1. Create a directory named auth in your template directory.
  2. Create a template of the same name that the built-in view is expecting to load.
  3. There is no step 3.

Also you can provide an url to the successful change with:

url(r'^password/$', 'django.contrib.auth.views.password_change', {'post_change_redirect' : '/password-changed/','template_name': 'password.html'},),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top