Installation¶
Install
django-usersettings
:pip install django-usersettings2
Add
usersettings
toINSTALLED_APPS
:INSTALLED_APPS = ( ... 'usersettings', ... )
Specify the custom
UserSettings
model as the default usersettings model for your project using theUSERSETTINGS_MODEL
setting in your settings.py (required):USERSETTINGS_MODEL='config.SiteSettings'
Add
usersettings.middleware.CurrentUserSettingsMiddleware
toMIDDLEWARE_CLASSES
(optional).
The middleware sets the usersettings
attribute on every request object, so you can use request.usersettings
to get the current usersettings:
MIDDLEWARE_CLASSES=(
...
'usersettings.middleware.CurrentUserSettingsMiddleware',
...
),
6. The current usersettings are made available in the template context when your
TEMPLATE_CONTEXT_PROCESSORS
setting contains usersettings.context_processors.usersettings
:
TEMPLATE_CONTEXT_PROCESSORS = (
...
'usersettings.context_processors.usersettings',
...
)