Django static files not loading when DEBUG = False: how to fix it
Django static files not loading when DEBUG = False, with CSS and JS answering 404 in production, is Django working as designed: runserver serves static files only while DEBUG is on. Set STATIC_ROOT, run collectstatic, and have something serve that folder: WhiteNoise inside the app, or a web server or CDN. Missing staticfiles manifest entry means a template asks for a file that is not in the manifest collectstatic wrote.
By Livops team, the people who build and run LivopsUpdated
The page comes back without styles, and the browser’s network tab shows 404 for every file under /static/. It happens the moment DEBUG goes to False, locally or on the first deploy. The admin looks just as bare.
Nothing is broken: Django stops serving static files when DEBUG is off, on purpose[1]. This page explains why, gives the production setup in three pieces, lists the causes when the setup is there and the files still do not load, including ValueError: Missing staticfiles manifest entry, and shows how to test it locally before you deploy. For the whole production setup of a Django app, see Django hosting.
Why it works with DEBUG on and not with DEBUG off
With django.contrib.staticfiles in INSTALLED_APPS, runserver serves static files for you when DEBUG is True[1]. Django calls that method grossly inefficient and probably insecure, unsuitable for production[1], so it is off whenever DEBUG is off. The same goes for the URL helpers people add to urls.py: static() works only in debug mode[1], and staticfiles_urlpatterns() only when DEBUG is True[2].
There is a switch, runserver --insecure, that serves static files even with DEBUG off. Django says it is only for local development, should never be used in production, and does not work with ManifestStaticFilesStorage[2].
What production needs
Three pieces: a folder, a command that fills it, and something that serves it.
1. STATIC_ROOT, the folder. The absolute path where collectstatic collects static files for deployment[3]. Django’s warning: it should be an initially empty destination folder, not a place to keep your static files permanently; those live in each app’s static/ folder and in STATICFILES_DIRS[3]. It must also differ from MEDIA_ROOT[3].
2. collectstatic, the command. python manage.py collectstatic copies all files from your static folders into STATIC_ROOT[1]; --noinput skips the prompt[2]. Run it whenever static files change, that is, on every deploy[4].
3. Something to serve STATIC_ROOT at STATIC_URL. Django’s deployment guide gives three ways: the web server in front of Django, a separate server for static files, or a cloud storage service or CDN[4]. On a platform the simplest is WhiteNoise, which serves the collected files from the Django app itself[8]:
# settings.py
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware", # right after SecurityMiddleware
# ... the rest
]
STORAGES = {
"default": {"BACKEND": "django.core.files.storage.FileSystemStorage"},
"staticfiles": {"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage"},
}
pip install whitenoise
python manage.py collectstatic --noinput
WhiteNoise’s middleware goes directly after SecurityMiddleware and before all other middleware[8]. Its storage backend is optional: it compresses the files and gives them hashed names so they can be cached forever, on top of Django’s ManifestStaticFilesStorage[8]. Without it, WhiteNoise still serves the files: leave the STORAGES lines out[8].
Causes, most common first
1. Nothing serves STATIC_ROOT
collectstatic ran and the files are in STATIC_ROOT, but the app runs under Gunicorn with no WhiteNoise and nothing in front of it. Add WhiteNoise as above, or point your web server at STATIC_ROOT under STATIC_URL[4]. If WhiteNoise is in requirements.txt but not in MIDDLEWARE, or sits below other middleware, move it to right after SecurityMiddleware[8].
2. collectstatic never ran, or ran before STATIC_ROOT was set
Then STATIC_ROOT is empty or missing, and there is nothing to serve. Without STATIC_ROOT, collectstatic stops with[7]:
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
Set STATIC_ROOT and run collectstatic as part of every deploy, before the app starts. WhiteNoise looks for files only at startup, so files added after the app has started are not seen[8]: collecting while the app already runs does not help until it restarts.
3. STATIC_URL is wrong, or the templates hard-code paths
STATIC_URL must end in a slash[3]. A relative value such as static/ is prefixed with the server’s SCRIPT_NAME, or / if it is not set[3], so static/ gives /static/ and also works when the app is served under a sub-path. It must also differ from MEDIA_URL[3].
In templates, build each URL with the static tag rather than typing /static/...[1]:
{% load static %}
<link rel="stylesheet" href="{% static 'css/site.css' %}">
The tag goes through the configured storage, so it picks up a changed STATIC_URL and, with a manifest storage, the hashed file name[1][2].
4. STATICFILES_STORAGE on Django 5.1 or later
Django 4.2 added the STORAGES setting and deprecated STATICFILES_STORAGE in favour of STORAGES["staticfiles"][5]. Django 5.1 removed STATICFILES_STORAGE[6]. A settings file copied from an older tutorial that still sets it gets the default storage instead of the one it names, WhiteNoise’s included. Move it into STORAGES as in the block above.
Keep the default entry when you do: a STORAGES you define replaces Django’s default value and is not merged with it[3], so a dictionary with only staticfiles leaves uploaded files without a storage.
5. ValueError: Missing staticfiles manifest entry
ValueError: Missing staticfiles manifest entry for 'css/site.css'
This one is a 500, not a 404. ManifestStaticFilesStorage, and WhiteNoise’s storage built on it, writes the hashed name of every file to staticfiles.json once, when collectstatic runs[2]. With DEBUG off, a template that asks for a file not in that manifest raises this error[2][7]. Three usual causes:
- The file does not exist where Django looks, often a typo in the
statictag.python manage.py findstatic --verbosity 2 css/site.cssshows every path Django searched[8]. collectstaticdid not run for this version, so the manifest is from an earlier one, or there is none. Run it on every deploy.- Tests run with the manifest storage. Django advises another storage in tests, because
collectstaticis not part of the normal test setup[2].
You can turn the error off: manifest_strict = False on a subclass of ManifestStaticFilesStorage[2], or WHITENOISE_MANIFEST_STRICT = False with WhiteNoise’s storage[8]. That hides a broken reference rather than fixing it.
A related error stops collectstatic itself: when a CSS file refers to a file that does not exist, the manifest storage cannot hash it and raises ValueError: The file '...' could not be found with ...[7]. Fix the path in the CSS, or add the missing file.
How to confirm the fix locally
Run with production settings, collected files and a production server, the way the platform will:
export DEBUG=0 ALLOWED_HOSTS=localhost
python manage.py collectstatic --noinput
gunicorn mysite.wsgi:application --bind 127.0.0.1:8000
curl -sI http://localhost:8000/static/admin/css/base.css | head -1
HTTP/1.1 200 OK means the static files are served without runserver; 404 means nothing serves them yet (cause 1 or 2). With a manifest storage, also open a few pages: a missing entry shows up as a 500 there, not on the CSS URL. This assumes your settings read DEBUG and ALLOWED_HOSTS from the environment and that django.contrib.admin is installed; otherwise use the path of one of your own files.
On Livops
collectstaticruns in the build. For a Django project, Livops runspython manage.py collectstatic --noinputduring the build, if the project hasdjango.contrib.staticfilesandSTATIC_ROOTis set. WithoutSTATIC_ROOTit does not run, and there is nothing to serve.- Serving is up to the app. With
DEBUG = FalseDjango serves no static files, so Livops’s docs point to WhiteNoise:pip install whitenoise,"whitenoise.middleware.WhiteNoiseMiddleware"right afterSecurityMiddleware, andSTATIC_ROOT = BASE_DIR / "staticfiles". - Do not collect at start. While the app runs, its code is read-only, so a start command that runs
collectstaticcannot write into aSTATIC_ROOTinside the project. The build is the place for it. - A failed build keeps the old version. If
collectstaticstops on an error, such as a CSS file pointing at a file that is missing, the deploy fails asbuild_failedwith the error in the build log, and the previous version keeps running. DEBUGfrom Variables. PutDEBUGandSECRET_KEYin Variables, read them insettings.py, and deploy again after changing them.
What Livops does for Django: Frameworks. The other checks after the first deploy: DisallowedHost: Invalid HTTP_HOST header and CSRF verification failed.
Questions
Why do static files work with DEBUG = True and break with DEBUG = False?
With django.contrib.staticfiles installed and DEBUG on, runserver serves static files itself. Django calls that grossly inefficient and probably insecure, so it stops when DEBUG is off. In production something else has to serve them.
Can I just run runserver with --insecure?
Only on your own machine. Django's docs say --insecure is for local development and should never be used in production, and it does not work with ManifestStaticFilesStorage.
What is the difference between STATIC_ROOT and STATICFILES_DIRS?
STATICFILES_DIRS lists extra folders where your static files live permanently. STATIC_ROOT is an initially empty folder that collectstatic copies everything into for deployment. Never keep your own files in STATIC_ROOT.
Should I use STATICFILES_STORAGE or STORAGES?
STORAGES. Django 4.2 added it and deprecated STATICFILES_STORAGE, and Django 5.1 removed STATICFILES_STORAGE. Set the backend under STORAGES with the staticfiles key, and keep the default key too, because STORAGES replaces the default value instead of merging with it.
What does Missing staticfiles manifest entry mean?
The manifest storage could not find the file your template asked for in staticfiles.json. Either the file does not exist where Django looks, often a typo in the static tag, or collectstatic was not run for this version. python manage.py findstatic --verbosity 2 with the path shows where Django searched.
Does WhiteNoise need a CDN or Nginx in front?
No. WhiteNoise serves the collected files from your Django process. A CDN or a separate web server is another way to serve STATIC_ROOT, not a requirement.
Does Livops run collectstatic for me?
Yes, during the build, when the project has django.contrib.staticfiles and STATIC_ROOT is set. Serving the files is still up to the app, which is why Livops's docs point to WhiteNoise.
Sources
- Django docs — How to manage static files (docs.djangoproject.com). Checked .
- Django docs — The staticfiles app (docs.djangoproject.com). Checked .
- Django docs — Settings (docs.djangoproject.com). Checked .
- Django docs — How to deploy static files (docs.djangoproject.com). Checked .
- Django docs — Django 4.2 release notes (docs.djangoproject.com). Checked .
- Django docs — Django 5.1 release notes (docs.djangoproject.com). Checked .
- Django source — django/contrib/staticfiles/storage.py (6.1) (raw.githubusercontent.com). Checked .
- WhiteNoise — Using WhiteNoise with Django (whitenoise.readthedocs.io). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Django appRelated
- Django hosting in 2026: how to deploy a Django app, and whereFor most Django apps, a platform that deploys from Git is the right pick: Render and DigitalOcean App Platform are the simplest fixed monthly prices, Fly.io is the cheapest in dollars, Railway bills by usage, and a VPS is for when you want root. Livops fits Django apps whose users are in Uzbekistan, at 39 credits a month. Below: prices and free tiers side by side, a Django deployment checklist, and how to host a Django project on Livops.
- DisallowedHost: Invalid HTTP_HOST header — Django's 400 Bad RequestDjango received a request for a host name that is not in ALLOWED_HOSTS, so it answered 400 Bad Request. Add the domain the site is served on to ALLOWED_HOSTS, without https:// and without a port, or read the list from an environment variable, and redeploy.
- Forbidden (403) CSRF verification failed. Request aborted. — Django after deployForbidden (403) CSRF verification failed. Request aborted. means Django's CSRF middleware refused a POST. Right after moving behind HTTPS and a proxy, the usual reason is Origin checking failed: add the site's origin with its scheme, such as https://example.com, to CSRF_TRUSTED_ORIGINS. For CSRF cookie not set or CSRF token missing, put the csrf_token tag in the form or send the X-CSRFToken header.
- Gunicorn "Worker failed to boot": what it means and how to fix itGunicorn's worker could not load your application, so the master process shut down. The cause is the Python traceback printed just above the message: most often a missing package or variable, or a wrong module:variable path in the gunicorn command. Fix what the traceback names and the workers boot.
- 502 Bad Gateway after deploying: what it means and how to fix itThe proxy in front of your app reached for it and got no valid answer: nothing was listening on the port it tried, or the process closed the connection mid-request. After a deploy that is almost always one of five things: the app listens on the wrong port or on 127.0.0.1, it crashed on start, it was still starting, it ran out of memory, or the proxy points at the wrong port. The app's own log says which.
- ModuleNotFoundError: No module named — after a deployPython searched sys.path and could not find the module you import. After a deploy that almost always means the package is not in requirements.txt, is listed under a different name than the one you import, or the start command runs a Python that the packages were not installed into.