[Django]-Django 1.5 extend admin/change_form.html object tools

5👍

The problem is that admin/change_form.html in your {% extend %} block is getting resolved as project/app/templates/admin/change_form.html.

One solution is to create a subdirectory of templates named for your app – possibly project/templates/admin/app/change_form.html.

In order to override one or more of them, first create an admin directory in your project’s templates directory. This can be any of the directories you specified in TEMPLATE_DIRS.

Within this admin directory, create sub-directories named after your app.

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-vs-replacing-an-admin-template

2👍

That’s because you’re extending the template with itself. What I do is put my custom admin templates in templates/admin. Then in that same folder I symlink to the django admin folder (templates/admin/admin).

So my extends looks like:

 {% extends 'admin/admin/change_form.html' %}

Make sure you also override index.html if you want to go down that path.

0👍

The best way to do this that I have found is to use '..' to go up a couple of directories, then go back down into directories that should only be found in the Django code base.

As the Django templates are in something like "django/contrib/admin/templates/admin", I found that this worked me:

{% extends "../../admin/templates/admin/change_form.html" %}

If that still causes a clash with some other structure you have, you could go further:

{% extends "../../../contrib/admin/templates/admin/change_form.html" %}

or even:

{% extends "../../../../django/contrib/admin/templates/admin/change_form.html" %}

Although it is a little hacky, at least by doing the above you don’t have to use some other technique that involves copying the django source or setting up a symlink.

👤jcdude

Leave a comment