I am new to Django and currently customizing the admin section. I want to change the CSS based on the app I am working with. Is this possible? I've noticed that the system uses the CSS from the first static folder it finds. Is there a workaround for this?
I have tried creating a static folder in each app, but the chosen CSS is always from the first one.
Even when following this method, the app_name variable remains empty, even within the admin site. The default blue CSS is always loaded.
The file I'm working with is 'portale_ict/templates/admin/base_site.html'
{% extends "admin/base.html" %}
{% block title %}{% if subtitle %}
{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}
{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">Portale ICT Administration</a></h1>
{% endblock %}
{% load i18n static %}
{% block extrastyle %}
<h1>{{ app_name }}</h1>
{% if app_name == 'ict' %}
<link rel="stylesheet" type="text/css" href="{% static 'admin_color_green.css' %}"/>
{% elif app_name == 'ins' %}
<link rel="stylesheet" type="text/css" href="{% static 'admin_color_purple.css' %}"/>
{% endif %}
{% endblock %}
{% block nav-global %}
{% endblock %}
The current setup loads the green CSS all the time, which is not my desired outcome:
{% extends "admin/base.html" %}
{% block title %}{% if subtitle %}
{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}
{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">Portale ICT Administration</a></h1>
{% endblock %}
{% load i18n static %}
{% block extrastyle %}
<link rel="stylesheet" type="text/css" href="{% static 'admin_color_green.css' %}"/>
{% endblock %}
{% block nav-global %}
{% endblock %}
Appreciate any help or suggestions. Thank you.