In Django grappelli, how can I add my own css files to all the admin pages? Or is there a way to extend admin's base.html
template?
I found the complex solution. First of all, I found a python package which can help you to tell the Django Template Loader that your template has a highest priority in comparison with others.
pip install django-templateloaderwithpriorities
In your django settings file put next code:
TEMPLATE_LOADERS = ('templateloaderwithpriorities.Loader', ) + TEMPLATE_LOADERS TEMPLATE_LOADER_PRIORITIES = ['project/admin/templates']
project/static/css/admin/extra_admin.css
put your css.In project/admin/templates/admin/base_site.html
(not in base.html
!) put the next code:
{% extends 'admin/base.html' %}
{% load staticfiles %}
{% block javascripts %}
{{ block.super }}
<script>alert('OK')</script>
{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" href="{% static 'css/admin/extra_admin.css' %}">
{{ block.super }}
{% endblock %}
Everything also works fine with Django Grappelli.