Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable prefers-color-scheme: dark in django admin

I have dark mode enabled on Mac, but it looks awkward in django admin panel with ckeditor. Is it any option to disable it in Chrome or Django admin? I have already tried themes and browser extensions with no success.

enter image description here

like image 967
VictoriaSh Avatar asked Apr 21 '21 09:04

VictoriaSh


People also ask

How do I change the color of my Django admin panel?

Restart your application server and now you should be able to see a new color scheme added by the package. If you want to customize it further go to your admin and look for “themes” app and do customizations there.

How can I remove extra's from Django admin panel?

Take a look at the Model Meta in the django documentation. Within a Model you can add class Meta this allows additional options for your model which handles things like singular and plural naming. Show activity on this post. inside model.py or inside your customized model file add class meta within a Model Class.

How to change the color scheme in Django admin?

Change Admin color scheme 1 choose your desired colors 2 generate the css file " django_color.css " 3 place the file in your static folder More ...

What is prefers-color-scheme media query in Django?

The prefers-color-scheme media query was introduced in Django 3.2 and is used to provide a dark or light theme depending on the color scheme in the users browser. Now you can edit the hex values of the above CSS properties to change the color of your admin panel.

How do I change the default theme from dark to light?

1st way: The fastest way is to go to your OS Settings and change from your theme from Dark to Light. If you are using Linux, you might need gnome-tweaks to switch between themes. Let us consider that you are using a virtual environment named venv.

How do I change the color scheme of my application?

Restart your application server and voila now you should be able to see a new color scheme added by the package. If you want to customize it further go to your admin and look for "themes" app and do customizations there. A couple of My personal favorite customizations there apart from colors are:


Video Answer


4 Answers

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).

like image 187
GwynBleidD Avatar answered Oct 23 '22 17:10

GwynBleidD


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

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

{% block extrastyle %}
<style>
    @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;
        }
    }
</style>
{% endblock %}
like image 33
CuriousPanda Avatar answered Oct 23 '22 17:10

CuriousPanda


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...

like image 23
frnhr Avatar answered Oct 23 '22 17:10

frnhr


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

{% extends "admin/base.html" %}
{% block dark-mode-vars %}{% endblock %}
like image 2
pranjal0819 Avatar answered Oct 23 '22 15:10

pranjal0819