Snippet: Django in Cloud Run + Firebase Hosting
- john
- March 26, 2025
Some useful tips for running Django / Wagtail in Cloud Run and Firebase Hosting.
- This tutorial is a great resource: https://cloud.google.com/python/django/run
- Whitenoise gives a simple solution for static file serving from Django, and Firebase Hosting or CDN can provide caching.
- The following settings are needed:
# Cloudrun compatibility
https://firebase.google.com/docs/hosting/manage-cache#using_cookies
# "Only the specially-named __session cookie is permitted to pass through to # the execution of your app."
SESSION_COOKIE_NAME = "__session"
#
https://docs.djangoproject.com/en/5.1/ref/settings/#csrf-use-sessions
CSRF_USE_SESSIONS = True
Also:
CSRF_TRUSTED_ORIGINS
to resolve CSRF errorsUSE_X_FORWARDED_HOST = True
so Django can correctly determine the host domain