[Fixed]-Disable prefers-color-scheme: dark in django admin


It looks like you’re using some 3rd party theme for Django admin. I suggest checking if the maintainer of this theme wants to support Django 3.2 any time soon.

As for the quick fix for that, you can introduce your own stylesheet that will reset variables responsible for the dark theme. You can find the variables here.

To achieve that, create a separate css file in your static file directory, copy over the @media declaration from the code fragment mentioned above and paste the normal color scheme inside it (also to be found in the same code fragment). After that, create a admin/base_site.html template, fill it with this content or the equivalent from the theme you’re using and link your custom CSS in the extrastyle block (you may need to create that block by hand).


You can disable dark mode in Django 4.1 and above by overriding admin/base.html in your template. https://github.com/django/django/pull/14929

{% extends "admin/base.html" %}
{% block dark-mode-vars %}{% endblock %}


There’s an app for that.

pip install django-light, details at https://github.com/frnhr/django-light.

Full disclosure: I’m the author. Well, more like "packager", not much original code there…



as @GwynBleidD wrote, I changed my admin/base_site.html like this, and it works:

{% extends "admin/base_site.html" %}

{% block extrastyle %}
    @media (prefers-color-scheme: dark) { 
        :root {
            --primary: #79aec8;
            --primary-fg: #fff;

            --body-fg: #333;
            --body-bg: #fff;
            --body-quiet-color: #666;
            --body-loud-color: #000;

            --breadcrumbs-fg: #c4dce8;
            --breadcrumbs-bg: var(--primary);

            --link-fg: #447e9b;
            --link-hover-color: #036;
            --link-selected-fg: #5b80b2;

            --hairline-color: #e8e8e8;
            --border-color: #ccc;

            --error-fg: #ba2121;

            --message-success-bg: #dfd;
            --message-warning-bg: #ffc;
            --message-error-bg: #ffefef;

            --darkened-bg: #f8f8f8; /* A bit darker than --body-bg */
            --selected-bg: #e4e4e4; /* E.g. selected table cells */
            --selected-row: #ffc;

            --close-button-bg: #888; /* Previously #bbb, contrast 1.92 */
            --close-button-hover-bg: #747474;
{% endblock %}

Leave a comment