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

Uploaded Source

Built Distribution

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

Uploaded Python 3

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