Registry / web-framework / django-constance

django-constance

JSON →
library4.3.5pypypi✓ verified 24d ago

Django Constance is a Django app that enables dynamic settings management, allowing configuration values to be edited directly from the Django admin interface without requiring code changes or redeployments. It supports pluggable backends, including built-in Redis and database options, and is actively maintained with regular releases. The current version is 4.3.5.

pip install "django-constance[redis]"
INSTALL
IMPORT
SIG · DJANGO-CONSTANCE
D
django-constance
web-frameworkpythonv4.3.5
Install
1.8s avg
Import
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.3.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 23.5MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.8s · import 0.000s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

config
from constance import config
from constance import config

Install django-constance with your chosen backend (e.g., Redis). Add `constance` to your `INSTALLED_APPS`. Define your dynamic settings using the `CONSTANCE_CONFIG` dictionary in your `settings.py`, specifying a default value and a help text. Then, access these settings anywhere in your Python code by importing `config` from `constance` and using attribute access (e.g., `config.SITE_NAME`). If using the database backend, remember to run `python manage.py migrate`.

import os # settings.py # Add 'constance' to your INSTALLED_APPS. INSTALLED_APPS = [ # ... other Django apps 'constance', # 'unfold.contrib.constance', # If using Django Unfold, place before 'constance' ] # Configure backend (example for Redis) CONSTANCE_BACKEND = 'constance.backends.redisd.RedisBackend' CONSTANCE_REDIS_CONNECTION = { 'host': os.environ.get('REDIS_HOST', 'localhost'), 'port': int(os.environ.get('REDIS_PORT', 6379)), 'db': int(os.environ.get('REDIS_DB', 0)), } # Define your dynamic settings CONSTANCE_CONFIG = { 'SITE_NAME': ('My Awesome Site', 'The name of the website.'), 'MAINTENANCE_MODE': (False, 'Enable or disable maintenance mode.'), 'MAX_USERS': (1000, 'Maximum allowed users on the platform.'), } # In your Django view or anywhere in Python code: from constance import config def my_view(request): if config.MAINTENANCE_MODE: return HttpResponse("Site is under maintenance.") site_name = config.SITE_NAME max_users = config.MAX_USERS print(f"Current site name: {site_name}") print(f"Max users: {max_users}") # ... your view logic # Run Django migrations if using the database backend # python manage.py migrate
Debug
Known issues
breakingVersion 3.0.0 introduced backward-incompatible changes, dropping support for Python <3.7 and Django <3.2. Additionally, if you were using the database backend, the `constance.backends.database` entry must be *removed* from `INSTALLED_APPS`.
fix
Ensure your project runs Python >=3.7 and Django >=3.2. Remove `'constance.backends.database'` from `INSTALLED_APPS` if you are using the database backend.
affects: >=3.0.0
gotchaWhen using admin extensions (like Grapelli) or integrations (like `unfold.contrib.constance`), the order of `constance` in `INSTALLED_APPS` matters. It should typically be placed *before* these extensions to ensure correct template loading.
fix
Adjust the order in `INSTALLED_APPS` to place `'constance'` (and `'unfold.contrib.constance'` if applicable) before other admin-related apps or extensions.
affects: All versions
gotchaIn multi-instance deployments (e.g., Docker Swarm, Kubernetes), hashes generated by `django-constance` might differ between instances, preventing data from being saved via the admin.
fix
Set `CONSTANCE_IGNORE_ADMIN_VERSION_CHECK = True` in your `settings.py` to skip hash verification. Be aware of the implications if security is a major concern.
affects: All versions
gotchaSynchronous access to `config` (e.g., `config.MY_SETTING`) within asynchronous Django views is highly discouraged. It can block the event loop, degrade performance, and for the Database backend, Django's safety guards might raise a `SynchronousOnlyOperation` error.
fix
Avoid accessing `config` synchronously within async views. Consider refactoring to retrieve settings outside the async context or using an async-compatible method if available (though `django-constance` primarily offers synchronous access).
affects: All versions
gotchaWhen setting `MultiValueField` settings via the `constance` management command, separate field values must be provided as individual arguments, not as a single string. E.g., `manage.py constance set DATETIME_VALUE '2011-09-24' '12:30:25'` instead of `'2011-09-24 12:30:25'`.
fix
Pass each component of a `MultiValueField` as a distinct argument to the `constance set` management command.
affects: All versions
Upgrade
Version history
4.3.5latest on PyPI · released Mar 15, 2026
Audit
Dependencies
DjangorequiredCore framework dependency. Requires Django >=3.2 for Constance v3.0.0+.
redisoptionalRequired for the Redis backend.
Agent activity
26 hits · last 30 days
node
24
Resources
django-constance — pip install django-constance · libregistry