Django app integration¶
Add pulumi-django-azure to the Django project that runs on App Service.
Minimal settings wiring¶
from pulumi_django_azure.settings import * # noqa: F403
from pulumi_django_azure.settings import patch_django_settings_for_azure
INSTALLED_APPS = [
# ... your apps ...
"django.contrib.staticfiles",
]
MIDDLEWARE = [
# ... your middleware ...
]
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"OPTIONS": {
"context_processors": [
# ...
],
},
},
]
patch_django_settings_for_azure(INSTALLED_APPS, MIDDLEWARE, TEMPLATES)
patch_django_settings_for_azure will:
- Insert
collectfastabeforedjango.contrib.staticfiles - Append
pulumi_django_azure,django_rq, anddjango_tasks_rqif missing - Append
HealthCheckMiddleware - Insert
WagtailHostAliasMiddlewarebefore Wagtail’s redirect middleware when present - Append the
add_build_infocontext processor
Manual alternative¶
Without the patch helper:
from pulumi_django_azure.settings import * # noqa: F403
INSTALLED_APPS += ["collectfasta", "pulumi_django_azure", "django_rq", "django_tasks_rq"]
MIDDLEWARE += ["pulumi_django_azure.middleware.HealthCheckMiddleware"]
Place collectfasta before django.contrib.staticfiles.
What settings do on Azure¶
When App Service sets IS_AZURE_ENVIRONMENT=true (done by Pulumi), the imported settings configure Postgres with Entra tokens, Azure Storage/CDN, secure cookies, optional Redis and tasks, and logging. See Settings and env and Local vs production.
Health check¶
Pulumi configures App Service health checks at /health-check. The middleware serves that path, refreshes the DB token, probes the database, and can recycle Gunicorn workers on failure.
Override freely¶
Import Azure defaults first, then override any setting in your module afterward.