Skip to main content

Load different CSS in Django admin site when switching between dark/light mode

Project description

Django Theme CSS Loader

After Django introduced dark/light theme in 3.2, some styled widget looks bad in dark mode, or even unusable. For my use case, it was JSON Editor and highlight.js. These libraries support theming via CSS. Take highlight.js for example, you could use a dark theme CSS for dark mode, and a light theme CSS for light mode.

While this isn't the best way to support dark/light theme for your widget, it is definitely the easier way.

Setup

pip install django_theme_css_loader

Then add django_theme_css_loader to your INSTALLED_APPS

Example

from django.forms import widgets
from django_theme_css_loader.widgets import ThemeLoaderJS


class HighlightJSWidget(widgets.Widget):
    template_name = "highlightjs/hightlightjs.html"
    
    class Media:
        js = [
            ThemeLoaderJS(
                # you could also use a CDN address here
                light_css="highlightjs/css/light.css",
                dark_css="highlightjs/css/dark.css",
                media="all", # media attribute on the link element
            )
        ]

Demo

Demo GIF

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_theme_css_loader-1.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

django_theme_css_loader-1.0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file django_theme_css_loader-1.0.1.tar.gz.

File metadata

  • Download URL: django_theme_css_loader-1.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.1 Darwin/23.4.0

File hashes

Hashes for django_theme_css_loader-1.0.1.tar.gz
Algorithm Hash digest
SHA256 78634aacd40ca7dd9f392c1aeddb50aec13acc264025a6b2d0b8c3c95ec98794
MD5 7dfcf9954c6a3f3b1b8fd8fe1a4d3a87
BLAKE2b-256 937408bb4d59d81dbb53887219648b849e150a87152b9f50c930d505ad6baf28

See more details on using hashes here.

File details

Details for the file django_theme_css_loader-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_theme_css_loader-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce8212f817e0fbdf4860aa8027dfdb634c76a2ae52c4811f096d13d81b892e4d
MD5 93efd149225d7b5791f780a06136dc87
BLAKE2b-256 3de374dbc55b2a7498d37341e8405c3e0ae55c5361d55046c072aa351de62f63

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page