Django password change view form
Asked Answered
P

3

6

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.

Periodontics answered 4/12, 2012 at 20:55 Comment(0)
H
11

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.

Herdic answered 4/12, 2012 at 21:6 Comment(0)
E
6

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.
Eyelet answered 4/12, 2012 at 21:3 Comment(2)
Isn't it the other way around then? First on the project template directory and then fall back to the app?Idelia
By "your application" I mean the Django project. The template directory I referenced in "Step 1" is the primary template directory in the project. If you add a directory synonymous to one already present in Django, your template directory will override the built-in.Eyelet
C
0

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'},),
Castellano answered 2/10, 2014 at 21:34 Comment(1)
castilo, are you addressing accepted answer or the question? Try make your answer a bit more clearer regarding thisWaterish

© 2022 - 2024 — McMap. All rights reserved.