This allows an administrator of a django website to change the theme on the fly.
pip install django-dynamic-theme
- Add the following settings::
INSTALLED_APPS = [
...,
"django_dynamic_theme",
"compressor",
]
...
# Default setting but you can set it to some other path.
STATIC_URL = "static/"
STATIC_ROOT = "static"
STATICFILES_FINDERS = [
...,
"compressor.finders.CompressorFinder",
]
COMPRESS_PRECOMPILERS = (("text/x-scss", "django_libsass.SassCompiler"),)
MIDDLEWARE = [
...,
"django_dynamic_theme.middleware.MissingThemeHandleMiddleware",
]
TEMPLATES = {
"OPTIONS": {
"context_processors": [
...,
"django_dynamic_theme-context_processor.theme",
]
}
}
-
Run
python manage.py migrate
-
Assuming you have
base.html
add this to it before the<body>
tag:
<html>
...
{% load compress %}
{% load static %}
{% compress css %}
<link type="text/x-scss" rel="stylesheet" href="{% static theme_file %}" />
...
</html>
- Visit
http://127.0.0.1:8000/admin/django_dynamic_theme/
to start customizing your theme.