Skip to main content

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

Metadata

Release files for django-theme-css-loader 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-theme-css-loader 1.0.1
File Size Uploaded
django_theme_css_loader-1.0.1.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-theme-css-loader 1.0.1
File Interpreter ABI Platform
django_theme_css_loader-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.1 kB

Release files / django_theme_css_loader-1.0.1.tar.gz

Download URL django_theme_css_loader-1.0.1.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
78634aacd40ca7dd9f392c1aeddb50aec13acc264025a6b2d0b8c3c95ec98794
BLAKE2b-256 checksum
How to use checksums
937408bb4d59d81dbb53887219648b849e150a87152b9f50c930d505ad6baf28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.1 Darwin/23.4.0

Release files / django_theme_css_loader-1.0.1-py3-none-any.whl

Download URL django_theme_css_loader-1.0.1-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce8212f817e0fbdf4860aa8027dfdb634c76a2ae52c4811f096d13d81b892e4d
BLAKE2b-256 checksum
How to use checksums
3de374dbc55b2a7498d37341e8405c3e0ae55c5361d55046c072aa351de62f63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.1 Darwin/23.4.0

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page