Settings

The django-logikal library provides a set of opinionated standard settings modules for local development, testing and production use.

You can simply import the appropriate settings module in your own settings files to benefit from a highly improved Django experience:

from django_logikal.settings import Settings
from django_logikal.settings.dynamic_site.dev import DevSettings

Settings(globals()).update(DevSettings)

Common Features

All settings modules include the following:

Settings Updates

Standard settings modules are provided as settings updates, which need to be applied to a Settings instance:

class django_logikal.settings.Settings(settings: dict[str, Any] | None = None)

Store and update the provided settings.

update(settings_update: type[SettingsUpdate]) Settings

Apply the given settings update to the stored settings.

You can specify your own settings updates by inheriting from the SettingsUpdate class:

class django_logikal.settings.SettingsUpdate
classmethod apply(settings: Settings) None

Apply the current settings update to the provided settings.

Tip

Static configuration options can be simply specified as class attributes, but it is also possible to dynamically modify the settings by overriding the apply() class method as follows:

from django_logikal.settings import Settings, SettingsUpdate

class AppSettings(SettingsUpdate):
    ROOT_URLCONF = 'app.website.urls'

    @staticmethod
    def apply(settings: Settings) -> None:
        settings['INSTALLED_APPS'] += ['app.website']

Tip

Note that settings updates can be chained, which makes combining the standard settings updates with your own custom settings updates simple and straightforward:

from django_logikal.settings import Settings
from django_logikal.settings.dynamic_site.dev import DevSettings
from app.settings.app import AppSettings

Settings(globals()).update(DevSettings).update(AppSettings)

Dynamic Site Settings

Provides email sending support (via Anymail and Amazon Simple Email Service), the paranoid middleware and a sensible content security policy (via django-csp).

Note

Requires the dynamic extra.

Note

When using the optional rest extra, the REST API endpoints are configured to be only accessible for session-authenticated users by default.

class django_logikal.settings.dynamic_site.dev.DevSettings

Standard settings for developing dynamic sites.

class django_logikal.settings.dynamic_site.testing.TestingSettings

Standard settings for testing dynamic sites.

class django_logikal.settings.dynamic_site.production.ProductionSettings

Standard production settings for dynamic sites.

Note

Secrets will be loaded from Google Secret Manager during import time. In particular, the secret key is loaded from the SECRET_KEY_PATH setting key (defaults to {project}-website-secret-key, where {project} is the project name in the pyproject.toml file), and the database configuration is loaded from the DATABASE_SECRETS_PATH setting key (defaults to {project}-website-database-secrets), which must contain a JSON string with keys hostname, port, database, username and password.

Static Site Settings

Provides static site generation support (via django-distill).

Note

Requires the static extra.

class django_logikal.settings.static_site.dev.DevSettings

Standard settings for developing static sites.

class django_logikal.settings.static_site.testing.TestingSettings

Standard settings for testing static sites.