Skip to main content

Allow a Django user to set a theme preference.

Project description

django-theme

Allow a Django user to set a theme preference.

Quickstart

  1. Install django-theme via pip:

    pip install django-theme
    
  2. Add theme to your INSTALLED_APPS in your project settings.py file:

    INSTALLED_APPS = [
        '...',
        'theme',
    ]
    
  3. Run migrate:

    python manage.py migrate
    
  4. Add the following to your context_processors setting:

    TEMPLATES = [
        {
            'BACKEND': '...',
            'OPTIONS': {
                'context_processors': [
                    '...',
                    '...',
                    'theme.context_processors.theme',
                ],
            },
        },
    ]
    
  5. 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 %}">
    
  6. The Theme model defines a one-to-one relationship with the User 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

This version

0.3

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 details)

Uploaded Source

Built Distribution

django_theme-0.3-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file django-theme-0.3.tar.gz.

File metadata

  • Download URL: django-theme-0.3.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.10

File hashes

Hashes for django-theme-0.3.tar.gz
Algorithm Hash digest
SHA256 1bc380062f4b876c26e71c4433797877de36814473f896991a01fa3d22095c92
MD5 3109c6dfa6ef2627d9dab29bc18b001e
BLAKE2b-256 aa9e64def074dedf7a9012b9ecba5a6f253d61d605e3cb5f439f136a342527c6

See more details on using hashes here.

File details

Details for the file django_theme-0.3-py3-none-any.whl.

File metadata

  • Download URL: django_theme-0.3-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.10

File hashes

Hashes for django_theme-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bf7856327c9585f2b71c48087194371294806f150c9fce8c2736934c819bae8b
MD5 1ab205f449bb23ee34cfe9edfa1a5e32
BLAKE2b-256 3a9734fbe23e13830b33fe06431d702dc50940c6e103b61c6c5dde9be2225544

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