Static files & frontend builds for Django in production
collectstatic, WhiteNoise, CDNs, cache busting, and bundlers like Vite and Tailwind in production.
Static files are your CSS, JavaScript, and images, collected on every release and served by Nginx, WhiteNoise, or a CDN. With hashed names they can be cached forever.
The guides cover serving them correctly, frontend builds with Vite or Tailwind, cache busting, and the errors that turn them into 404s, 403s, or unstyled pages.
Set it up
Guides that take this from nothing to running in production.
- Django Static vs Media Files in Production
Many Django deployments break because static files and media files are treated as the same thing.
- How to Serve Django Static Files with WhiteNoise
Django does not safely serve static files in production by default. With DEBUG=False, you still need a production path for CSS, JavaScript, fonts, and images collected from your...
- Serve Django Static Files Through CloudFront
Serve Django static files from CloudFront: S3 with origin access control or origin pull, hashed filenames, immutable caching, and CORS.
- Deploy Django with Vite Frontend Assets
Ship Vite-built JavaScript and CSS with Django in production: manifest-based asset tags with django-vite, a Node build stage, collectstatic, cache headers, and avoiding dev-server leaks.
- Build Tailwind CSS for Django in Production
Build a minified Tailwind CSS file for Django releases: scanning templates and Python code, the standalone CLI without Node, Docker build stages, collectstatic hashing, and missing-class bugs.
- Compile Django Translations During Deployment
Ship Django translations reliably: run compilemessages in CI or a Docker build stage with gettext, ignore virtualenvs, validate .po files, restart workers, and verify every language in production.
- WhiteNoise vs Nginx for Django Static Files
Compare serving Django static files with WhiteNoise inside the app versus Nginx or a CDN: setup, compression and cache headers, performance, containers and PaaS, media files, and the setup that suits each deployment.
- Serve Django Static and Media Files Through Bunny CDN
Put Bunny CDN in front of a Django site: create a pull zone for WhiteNoise static files or an object storage origin, use hashed file names with long cache headers, serve media from Bunny Storage with django-storages, and purge or sign URLs when needed.
- Serve a Django Site Through Fastly
Put Fastly in front of Django: configure the origin and host header, cache anonymous pages with Surrogate-Control and surrogate keys, bypass logged-in users, purge by key from Django signals, and set shielding, TLS, and compression for static files.
- Serve Django and a React SPA on the Same Domain
Serve a React SPA and a Django API from one domain with Nginx: routing fallback, API proxying, cache headers, and CSRF-safe session auth.
- Serve Django Static Files on Kubernetes
Choose how to serve Django static files on Kubernetes: WhiteNoise inside the app image, an Nginx sidecar sharing an emptyDir, a separate static image, or object storage with a CDN, and avoid shared volumes, stale files, and collectstatic at pod start.
Run it well
Tuning, reliability, and operations once it works.
- Long-Lived Caching for Django Static Files
Cache Django static files for a year without stale assets: manifest hashing, immutable Cache-Control headers in Nginx and WhiteNoise, CDNs, and deploy order.
- Speed Up Django collectstatic to S3
Make collectstatic to S3 or other object storage fast: skip unchanged files, use storage backends that compare hashes, collect locally then sync with the AWS CLI, skip post-processing where safe, and run it once per release in CI instead of on every server.
- Purge the Cloudflare or CDN Cache After a Django Deploy
Decide what to purge from Cloudflare or another CDN after deploying Django: rely on hashed static file names, purge cached HTML by URL or tag, automate purges from CI with an API token, avoid purge-everything, and keep old assets available during rollouts.
Check it
Review lists to run before launch or after a change.
- Django Static Files Production Checklist
A production checklist for Django static files: STATIC_ROOT and collectstatic in the build, manifest storage for cache busting, serving with WhiteNoise, Nginx, or a CDN, cache headers, compression, frontend bundles, and admin assets.
Fix it
Errors and symptoms, each traced to a cause and a fix.
- Django Static Files Not Loading in Production: Fix Guide
A common production failure is that your Django app loads, but CSS, JavaScript, or Django admin assets are missing.
- Fix Django Admin CSS Missing in Production
Fix an unstyled Django admin in production: collectstatic, STATIC_URL and alias paths, WhiteNoise order, MIME types, subpath deployments, CSP, and mixed content.
- Fix collectstatic Errors in Django Deployments
Fix Django collectstatic failures: missing STATIC_ROOT, broken CSS references, source map errors, duplicate paths, permissions, and build-time settings.
- Fix Django Static Files 404 in Docker
Fix Django static files returning 404 in Docker: collectstatic in the image, shared volumes between Django and Nginx, bind mounts hiding files, and WhiteNoise setup.
- Fix "Missing staticfiles manifest entry" in Django
Fix ValueError: Missing staticfiles manifest entry in Django production: collectstatic not run, wrong STATIC_ROOT, typos in static paths, missing apps, and build-time settings mismatches.
- Fix Django Static Files Served with the Wrong MIME Type
Fix Refused to apply style and Expected a JavaScript module script errors for Django static files: HTML 404 pages served as CSS, missing mime.types in Nginx, .mjs and .wasm types, and WhiteNoise.
- Fix "You're using the staticfiles app without having set STATIC_ROOT"
Fix the Django ImproperlyConfigured error You’re using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path: set STATIC_ROOT correctly, keep it separate from STATICFILES_DIRS, and run collectstatic in deploys.
- Fix Django staticfiles.W004: STATICFILES_DIRS Directory Does Not Exist
Fix the Django staticfiles.W004 warning that a STATICFILES_DIRS directory does not exist, and the related E002 error: build paths from BASE_DIR, commit empty directories, check .dockerignore, and keep STATIC_ROOT out of STATICFILES_DIRS.
- Fix Nginx 403 Forbidden on Django Static Files
Fix 403 Forbidden for Django static and media files served by Nginx: directory traversal permissions, file modes, alias paths, SELinux contexts, and verification.
- Fix Django Static Files Not Updating With a Docker Volume
Fix Django CSS and JavaScript that stay old after a Docker deploy because a named volume hides the new collectstatic output: understand how volumes shadow image files, collect at the right time, and share static files with Nginx correctly.
- Fix Heroku "Error While Running collectstatic" for Django
Fix the Heroku Python build error while running python manage.py collectstatic --noinput: read the hidden traceback, set STATIC_ROOT, avoid settings that need runtime config vars at build time, and fix WhiteNoise manifest errors.
- Fix Django SuspiciousFileOperation: Joined Path Is Outside the Base Path
Fix Django SuspiciousFileOperation errors such as the joined path is located outside of the base path component and detected path traversal attempt: build upload paths safely, avoid absolute names and leading slashes, and handle static files referenced with ../.