[Django]-Override specific admin css files in Django

2👍

I’m looking for a solution short of copying all the admin media files into my project and changing admin’s static directory

I don’t think there is really an alternative. You copy the media files into a new directory and while you start the server pass the adminmedia command line argument, like

python manage.py runserver --adminmedia=./myadminmedia

In any case, when you run it on production server, the admin media has to be served from a good static serving server, for which, you can point this new path.

Reference from the Docs: https://docs.djangoproject.com/en/1.3/ref/django-admin/#django-admin-option—adminmedia

👤lprsd

10👍

What I’m doing to achieve that is to override base_site.html template like this:

{% block blockbots %}
<link rel="stylesheet" type="text/css" href="/media/css/my_admin.css" />
{{ block.super }}
{% endblock %}

I put the CSS in blockbotsinstead of extrahead to be sure that is loaded at the end, so it will override all others CSS.

0👍

Probably you can hack your urls.py file and point only a single media URL to be served from a local folder while the others are served from the Django directory(in development mode).

Leave a comment