Skip to main content

django-livesettings3

Tests PyPI version codecov

This is a Python 3 Port of django-livesettings that has been tested with Python 3.8-3.13 and Django 3.2-5.2.

django-livesettings3 provides the ability to configure settings via an admin interface, rather than by editing settings.py. In addition, livesettings allows you to set sane defaults so that your site can be perfectly functional without any changes. Livesettings uses caching to make sure this has minimal impact on your site’s performance. Finally, if you wish to lock down your site and disable the settings, you can export your livesettings and store them in your settings.py. This allows you have flexibility in deciding how various users interact with your app.

Requirements

Install

$ pip install git+https://github.com/kunaldeo/django-livesettings3

Quickstart

Adding livesettings to your project

Add livesettings to settings.py

INSTALLED_APPS = (
  'django.contrib.admin',
  'livesettings',
  'myapp'
)

It is high recommended to configure a global cache (like Redis) in production for multiprocess servers or you will see the outdated data.

Add livesettings.urls to urlpatterns in urls.py

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^settings/', include('livesettings.urls')),
]

Checkout the Sample screenshot of livesetting editor

Create config.py

Create config.py within your app directory where your models.py is located. We will use config.py to register the settings value.

config.py

from django.utils.translation import gettext_lazy as _
from livesettings.functions import config_register
from livesettings.values import ConfigurationGroup, PositiveIntegerValue, MultipleStringValue


# Config group to hold all the configs
MYAPP_GROUP = ConfigurationGroup('MyApp', _('My App Settings'), ordering=0)

# When ordering parameter is not passed, all inputs are sorted by name
config_register(PositiveIntegerValue(
    MYAPP_GROUP,
    'NUM_IMAGES',
    description=_('Number of images to display'),
    help_text=_("How many images to display on front page."),
    # if no help_text is given, Default falue is displayed
    default=5
))

# Another example of allowing the user to select from several values
config_register(MultipleStringValue(
    MYAPP_GROUP,
    'MEASUREMENT_SYSTEM',
    description=_("Measurement System"),
    help_text=_("Default measurement system to use."),
    choices=[('metric', _('Metric')),
             ('imperial', _('Imperial'))],
    default="imperial"
))

Activate config.py

To activate the config.py you need to import config from models.py file.

from * import config

Linter Warning: Becareful of PyCharm's Optimize Imports, it may remove this line as it is never called directly!

Accessing Values in view

You can use config_value method to read the values store in livesttings

from django.shortcuts import render
from livesettings.functions import config_value


def index(request):
    image_count = config_value('MyApp', 'NUM_IMAGES')
    # Note, the measurement_system will return a list of selected values
    # in this case, we use the first one
    measurement_system = config_value('MyApp', 'MEASUREMENT_SYSTEM')
    return render(request, 'myapp/index.html',
                  {'image_count': image_count,
                   'measurement_system': measurement_system[0]})

Security and Permissions

In order to give non-superusers access to the /settings/ views, open Django Admin Auth screen and give the user or to its group the permission livesettings|setting|Can change settting.

Checkout the permissions screenshot

The same permission is needed to view the form and submit. Permissions for insert or delete and any permissions for “long setting” are ignored.

Superusers will have access to this setting without enabling any specific permissions.

If you want to save a sensitive information to livesettings on production site (e.g. a password for logging into other web service) it is recommended not to grant permissions to livesettings to users which are logging in everyday. The most secure method is to export the settings and disable web access to livesettings as described below. Exporting settings itself is allowed only by the superuser.

Because of the security significance of livesettings, all views in livesettings support CSRF regardless of whether or not the CsrfViewMiddleware is enabled or disabled.

Exporting Settings

Settings can be exported by the http://127.0.0.1:8000/settings/export/ . After exporting the file, the entire output can be manually copied and pasted to settings.py.

Supported Data Types

Following Data Types are supported:

  • Boolean
  • Decimal
  • Duration
  • Float
  • Integer
  • Positive Integer (non negative)
  • String
  • Long string
  • Multiple strings
  • Long multiple strings
  • Module values
  • Password

List is not implemented. But it is easy to use with comma separated string. When using the value you can simply use csvstring.split(',')

Fork of https://bitbucket.org/bkroeze/django-livesettings.

Metadata

Release files for django-livesettings3 1.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-livesettings3 1.7.0
File Size Uploaded Provenance
django_livesettings3-1.7.0.tar.gz 52.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-livesettings3 1.7.0
File Interpreter ABI Platform
django_livesettings3-1.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 124.8 kB

Release files / django_livesettings3-1.7.0.tar.gz

Download URL django_livesettings3-1.7.0.tar.gz
Size 52.3 kB
Tags Source
SHA-256 checksum
How to use checksums
24ab9b23852559639aeb51efe0721c7e8454d039a87576b989bf8438fcc7c4c7
BLAKE2b-256 checksum
How to use checksums
efbf46f0f384c4888fa039552e2fa244ca957a622813474d27e2db06da24bb2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / django_livesettings3-1.7.0-py3-none-any.whl

Download URL django_livesettings3-1.7.0-py3-none-any.whl
Size 72.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0e28dd309f65d3e7234990af9808d0149451957e4e155ee4d19770548d65939
BLAKE2b-256 checksum
How to use checksums
7c1e27228443ece1d3a64a483f0c75655851e194337753943899a40cd53d5c11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for django-livesettings3 1.7.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page