django-settings-export
raw JSON → 1.2.1 verified Fri May 01 auth: no python
Django app that allows you to export certain settings to templates via a context processor. Current version 1.2.1. Low maintenance; last release 2020-06-01.
pip install django-settings-export Common errors
error TemplateDoesNotExist at / ↓
cause Missing SETTINGS_EXPORT in INSTALLED_APPS, or wrong app label.
fix
Add 'SETTINGS_EXPORT' to INSTALLED_APPS (uppercase).
error django.template.exceptions.TemplateSyntaxError: 'settings' is not a valid tag or filter ↓
cause The context processor variable name 'settings' conflicts with Django's built-in 'settings' template tag from django.core.context_processors.
fix
Set SETTINGS_EXPORT_VARIABLE_NAME = 'exported_settings' or similar to avoid conflict.
Warnings
gotcha The app name in INSTALLED_APPS and context processor path is 'SETTINGS_EXPORT' (all caps). Many people mistakenly use 'settings_export' or 'django_settings_export'. ↓
fix Use exactly 'SETTINGS_EXPORT' (uppercase).
gotcha The context processor adds all settings from SETTINGS_EXPORT list to the template context under a variable named 'settings' (or custom name via SETTINGS_EXPORT_VARIABLE_NAME). This may conflict with other context processors that also add a 'settings' variable. ↓
fix Use SETTINGS_EXPORT_VARIABLE_NAME to set a unique variable name (e.g., 'my_settings').
Imports
- settings_export wrong
from settings_export import settings_exportcorrectfrom SETTINGS_EXPORT.settings_export import settings_export
Quickstart
# settings.py
INSTALLED_APPS = [
...
'SETTINGS_EXPORT',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'OPTIONS': {
'context_processors': [
...
'SETTINGS_EXPORT.settings_export.settings_export',
],
},
},
]
SETTINGS_EXPORT = [
'DEBUG',
'SITE_NAME',
]
# In template:
# {{ settings.DEBUG }}