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.
- [Django]-Dynamic SEO-friendly URLs
- [Django]-Django Generated polish plurals form in .po file not working
- [Django]-How to redirect via TemplateView.as_view to .html file
- [Django]-What is fuzzy strings in gettext?
- [Django]-How to fix "fatal error: Carbon/Carbon.h: No such file or directory", when trying to deploy to Heroku – (Django)
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.
- [Django]-Detect the language & django locale-url
- [Django]-Gunicorn not running can't connect to sock file
- [Django]-Apache2: /etc/apache2/sites-available is missing on macos
- [Django]-I m confused about the ready function used inside app.py
- [Django]-Django-orm : How to update one-to-one relation field value