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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78634aacd40ca7dd9f392c1aeddb50aec13acc264025a6b2d0b8c3c95ec98794 |
|
MD5 | 7dfcf9954c6a3f3b1b8fd8fe1a4d3a87 |
|
BLAKE2b-256 | 937408bb4d59d81dbb53887219648b849e150a87152b9f50c930d505ad6baf28 |
File details
Details for the file django_theme_css_loader-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: django_theme_css_loader-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.1 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce8212f817e0fbdf4860aa8027dfdb634c76a2ae52c4811f096d13d81b892e4d |
|
MD5 | 93efd149225d7b5791f780a06136dc87 |
|
BLAKE2b-256 | 3de374dbc55b2a7498d37341e8405c3e0ae55c5361d55046c072aa351de62f63 |