Skip to Content
FeaturesIntegrationsIntegration Patterns

Integration Patterns

Every integration follows one pattern: you set a typed field on DjangoConfig, and a generator turns it into the matching Django settings. Nothing is registered by hand.

Settings generation

DjangoConfig.get_all_settings() runs SettingsOrchestrator.generate() (django_cfg.core.generation). It builds the settings dictionary in dependency order:

  1. core, templates, static
  2. databases, caches
  3. security, email, logging, i18n, limits, sessions, testing
  4. third-party apps (admin site, Constance, Telegram)
  5. API (DRF, drf-spectacular, OpenAPI groups)
  6. OAuth, Django-RQ, Tailwind, payments

The result is computed once and cached on the config instance.

# api/settings.py from .config import config globals().update(config.get_all_settings())

Where an integration lives

Each integration has one generator under django_cfg/core/generation/integration_generators/ (api.py, oauth.py, django_rq.py, sessions.py, tailwind.py, third_party.py). The generator reads its config field and returns a settings fragment. The set of installed apps and middleware comes from config.get_installed_apps() and config.get_middleware().

Config fieldGenerates
openapi_client (OpenAPIClientConfig)REST_FRAMEWORK, SPECTACULAR_SETTINGS and the per-group schema URLs
django_rq (DjangoRQConfig)RQ_QUEUES, worker and scheduler settings
payments (PaymentsConfig)CFG_PAYMENTS_OWNER_MODEL when the app is enabled
admin_site (AdminSiteConfig)CFG_ADMIN_SITE, read by CfgAdminSite

DRF is reloaded after generation

DRF reads REST_FRAMEWORK once and caches it. If DRF was imported before django-cfg generated its settings, the cache would hold the defaults, so get_all_settings() calls reload_drf_api_settings() before it returns. Do not import rest_framework.settings state yourself ahead of the config.

Adding your own settings

Anything django-cfg has no field for goes in settings.py after the generated values:

# api/settings.py from .config import config globals().update(config.get_all_settings()) MY_FEATURE_FLAG = True

See the OAuth and Django-RQ pages for two complete integrations.

Last updated on