Allow a Django user to set a theme preference.
Project description
django-theme
Allow a Django user to set a theme preference.
Quickstart
-
Install django-theme via pip:
pip install django-theme
-
Add
theme
to yourINSTALLED_APPS
in your project settings.py file:INSTALLED_APPS = [ '...', 'theme', ]
-
Run migrate:
python manage.py migrate
-
Add the following to your
context_processors
setting:TEMPLATES = [ { 'BACKEND': '...', 'OPTIONS': { 'context_processors': [ '...', '...', 'theme.context_processors.theme', ], }, }, ]
-
In your template, you can then use the following snippet (theme options are 'system', 'dark' and 'light'):
<body class="{% spaceless %} {% if theme == 'dark' %} dark-theme {% endif %} {% endspaceless %}">
-
The
Theme
model defines a one-to-one relationship with theUser
model. Therefore, the theme object for a user can be retrieved by using:theme = user.theme
Compatibility
- Compatible with Python 3.8 and above.
- Compatible with Django 3.2 and above.
Versioning
This project follows semantic versioning (SemVer).
License and code of conduct
Check the root of the repo for these files.
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
django-theme-0.3.tar.gz
(15.9 kB
view hashes)
Built Distribution
django_theme-0.3-py3-none-any.whl
(17.3 kB
view hashes)
Close
Hashes for django_theme-0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf7856327c9585f2b71c48087194371294806f150c9fce8c2736934c819bae8b |
|
MD5 | 1ab205f449bb23ee34cfe9edfa1a5e32 |
|
BLAKE2b-256 | 3a9734fbe23e13830b33fe06431d702dc50940c6e103b61c6c5dde9be2225544 |