Startup & Validation
Django-CFG runs a set of focused startup hooks from AppConfig.ready() and registers a few Django system checks. Each hook is isolated in its own module under django_cfg/startup/, is idempotent, and a failure logs a warning without stopping the process. The startup banner is quiet by default.
Startup Validation Hooks
These hooks run automatically from DjangoCfgConfig.ready(). They are each isolated in their own module under django_cfg/startup/.
DRF Authentication Patch (drf_patch.py)
patch_drf_authentication() re-applies the JWT-aware DRF Request._authenticate monkey-patch after all apps are loaded.
The patch ensures that AuthenticationFailed raised by non-JWT backends does not block JWT authentication when the request carries a JWT Bearer token. This allows projects to register API-key or other custom authentication backends alongside JWTAuthenticationWithLastLogin without modifying those backends.
The patch is idempotent — applying it twice replaces the method with the same implementation.
See ./middleware for full details on the JWT authentication class.
Type Stubs (type_stubs.py)
install_type_stubs() runs only in development environments (DJANGO_ENV != "production").
It writes typings/rest_framework/serializers.pyi and patches pyrightconfig.json so that Pyright narrows serializer.validated_data to dict[str, Any] after is_valid(raise_exception=True) is called. This eliminates a common Pyright false-positive in DRF views.
The hook is a no-op in production and silently swallows all exceptions to avoid breaking the server start.
Media Types (mime_types.py)
register_media_types() runs first and registers media types that Python’s mimetypes table lacks in slim containers (for example .webp). Without it, django-storages uploads such files to S3/R2 as application/octet-stream.
DRF Datetimes in UTC (drf_datetime_utc.py)
DRF datetimes are rendered under timezone.override(UTC), because the response format carries a literal Z and TimezoneMiddleware activates the visitor’s zone. Input parsing still uses the active zone.
System Checks
These modules register checks when imported; they never stop startup.
| Check | Meaning |
|---|---|
django_cfg.W011 | Production with the admin at the default /admin/: set admin_access.path |
django_cfg.W012 | admin_access asks for a path or enabled=False but the admin is still mounted elsewhere (for example a hard-coded path("admin/", admin.site.urls)) |
django_cfg.W020 | security_domains repeats a host that a declared site already allows |
| command shadowing | A project management command is silently replaced by a django-cfg command of the same name (the earlier app in INSTALLED_APPS wins) |
Startup Information Display
By default django-cfg is quiet:
- a development server on a terminal prints one line:
django-cfg <version> . <project> . <env> - other commands (
shell,migrate, tests), gunicorn/daphne workers and containers without a TTY print nothing
Opt in to the verbose block with DJANGO_CFG_BANNER=1 or startup_banner=True. Then
startup_info_mode selects its shape.
from django_cfg import DjangoConfig, StartupInfoMode
class MyProjectConfig(DjangoConfig):
project_name: str = "My Project"
startup_banner: bool = False # True, or DJANGO_CFG_BANNER=1
startup_info_mode: StartupInfoMode = StartupInfoMode.FULLDJANGO_CFG_BANNER=1 python manage.py runserverstartup_info_mode has no effect while the banner is off. There is no DJANGO_STARTUP_INFO_MODE environment variable: set the field in the config.
Display modes
| Mode | Shows |
|---|---|
NONE | One line: version, environment, project, update notice |
SHORT | Compact header, apps grid (up to 8), essential endpoints (up to 6), status metrics, update notice, commands summary |
FULL | Everything in SHORT plus the configuration panel (version, environment, project, health URL), Constance fields by source, enabled apps and endpoints side by side, RQ queue status and worker commands, and the management command breakdown |
What the FULL block looks like
Django CFG Configuration
Version: 2.3.416
Environment: development
Project: My Django Project
Health: http://localhost:8000/healthz/ready
Enabled Apps Endpoints
- health - http://localhost:8000/healthz/ready
- commands - http://localhost:8000/cfg/commands/
- payments - http://localhost:8000/cfg/payments/Version and update information is cached, so repeated starts do not call the network each time.
Troubleshooting
- Nothing is printed: that is the default. Set
DJANGO_CFG_BANNER=1for the block; the one-line form needs a dev server (runserver) on a terminal. - Missing apps or endpoints: check the app is in
INSTALLED_APPSand its config section (for examplePaymentsConfig) is set. - Misaligned layout: use a terminal at least 120 characters wide.
AI Development Hints
With the verbose block on, FULL mode also prints hints for AI assistants about Django 5.2+ async patterns (aget(), acreate(), async for, sync_to_async()), controlled by the show_ai_hints field.
class MyProjectConfig(DjangoConfig):
show_ai_hints: bool = True # default True; set False to hide the hints