Skip to content
djust/docs
Appearance
Mode
djust.org →
Browse documentation

2 min read

Settings

The active theme pack and its behavior are configured under LIVEVIEW_CONFIG['theme'] in your Django settings.py.

LIVEVIEW_CONFIG = {
    'theme': {
        'pack': 'docs',
        'default_mode': 'dark',
        'enable_dark_mode': True,
        'persist_in_session': True,
        # 'cookie_namespace': 'docs',   # v0.9.0+
    },
}

Key reference

pack

Required. Name of a registered theme pack. Determines the bundled preset (colors), design system (typography / layout / etc.), and the pack's extra_css_vars block.

'pack': 'docs',          # docs.djust.org house theme
'pack': 'dracula',       # the classic dark
'pack': 'vercel',        # neutral white-on-near-black
'pack': 'catppuccin',    # warm pastels

To see every registered pack name:

from djust.theming import get_registry
print([p.name for p in get_registry().list_packs()])

default_mode

Default: 'light'.

Which mode the site renders for users who have not explicitly chosen one. Either 'light' or 'dark'. The user's explicit choice (if enable_dark_mode=True and they've toggled) overrides this.

'default_mode': 'dark',

enable_dark_mode

Default: True.

Whether the user-facing mode switcher is offered. If False, every visitor sees default_mode regardless of preference.

'enable_dark_mode': True,

persist_in_session

Default: True.

If True, a user's choice of pack and mode is stored in the session and restored on subsequent visits. If False, every visit starts fresh from the configured defaults.

'persist_in_session': True,

Default: None (no namespace). Available: v0.9.0+.

Cookies are scoped by domain — not by port. If you run multiple djust projects on localhost:8001 / localhost:8002 / localhost:8003, their theme cookies will overwrite each other without this setting. Set a unique namespace per project to keep them isolated:

# settings.py for docs.djust.org
'cookie_namespace': 'docs',

# settings.py for djust.org
'cookie_namespace': 'marketing',

The namespace is appended to the cookie name (e.g. djust_theme__docs), so each project gets its own slot.

Reading the active config in Python

from djust.theming import get_active_pack, get_active_mode

def my_view(request):
    pack = get_active_pack(request)       # ThemePack
    mode = get_active_mode(request)       # 'light' | 'dark'
    print(pack.name, pack.preset.display_name, mode)

Reading the active config in templates

The djust.theming.context_processors.theme context processor (enabled by default with djust.theming in INSTALLED_APPS) exposes the active state to every template:

{{ request.theme.pack.name }}      <!-- 'docs' -->
{{ request.theme.mode }}            <!-- 'light' | 'dark' -->

Use this for "which CTA color do I use" decisions in markup that needs to differ visibly between modes (rare — most cases should use CSS variables instead, see Tokens).

Switching packs at runtime

A pack name in settings is the default. Users (and your code) can switch at runtime; see Runtime switching for the API.

See also

  • Tokens — what variables the active pack emits.
  • Runtime switching — how the user's override is applied per request.

Spotted a typo or want to improve this page? Edit on GitHub →