Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I override Django's administrative change password page?

I'd like to override Django's administrative "Change Password" page (change_password.html). As such, I've placed Django's "/contrib/admin/templates/registration/password_change_form.html" in my project's "/templates/admin/registration/password_change_form.html" directory. Unfortunately, this doesn't seem to do the trick.

At this point, I'm stumped. I'm guessing it has something to do with Django's /contrib/auth/urls.py file (which directs the the admin change password call to "django.contrib.auth.views.password_change"), but admin template changes have been trivial so far and I'm surprised this one doesn't follow suit.

Any thoughts?

like image 468
Huuuze Avatar asked Jan 15 '09 16:01

Huuuze


3 Answers

You must use:

templates/registration/password_change_form.html

If you still see the Django's Admin template, you must change the order of your INSTALLED_APPS (e.g if your template is inside some app, this app must appear before django.contrib.admin in INSTALLED_APPS)

https://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.views.password_change

like image 197
semente Avatar answered Sep 28 '22 17:09

semente


A quick look at the source indicates you should place the template in:

/templates/registration/password_change_form.html

Note bene: there is no 'admin/' in there.

like image 24
Peter Rowell Avatar answered Sep 28 '22 18:09

Peter Rowell


I had the same problem; I believe it has to do how django template loaders work.

If you are using something like

TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

With something like TEMPLATE_DIRS = ( os.path.join(PROJECT_DIR, 'templates'), )

Then you would expect that (where localstore is the name of your local satchmo overrides) localstore/templates/registration/password_change_form.html would work. However, it doesn't for the password_change_form because the admin is overwriting it. So, it goes something like:

  1. File loader template dirs (e.g. templates)
  2. (django admin templates)
  3. Local apps template dirs

So, the solution for me was to move my registration template overrides from my localstore/templates directory to the /templates directory of the project.

like image 37
tmarthal Avatar answered Sep 28 '22 16:09

tmarthal