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]"Verified import paths — ran on the pinned version, not inferred.
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`.
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.
Adjust the order in `INSTALLED_APPS` to place `'constance'` (and `'unfold.contrib.constance'` if applicable) before other admin-related apps or extensions.
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.
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).
Pass each component of a `MultiValueField` as a distinct argument to the `constance set` management command.