Guides / ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting
ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting
You ran collectstatic (or deployed) and got ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. Django has nowhere to copy your static files to. Set STATIC_ROOT and run it again.
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path.
What it means
collectstatic gathers the static files of every installed app, plus your STATICFILES_DIRS, into a single folder so a web server can serve them. That folder is STATIC_ROOT. It is empty by default because Django can't guess where on your server it is safe to write. The same error appears when something else asks for the folder, such as a manifest storage backend.
This is the same root cause as Django static files not loading in production, hit one step earlier: there the files are missing at runtime, here the command that would collect them can't start.
Why it happens
- You never set it.
startprojectsetsSTATIC_URLbut notSTATIC_ROOT, because you don't need it withrunserver. - It is set only in a different settings file. You added it to
production.pybut the command runs withDJANGO_SETTINGS_MODULEpointing atbase.pyorlocal.py, or the other way around. - It is read from an environment variable that is not set during the build. The build step has no
STATIC_ROOTand the setting ends up empty.
The fix
# settings.py
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
python manage.py collectstatic --noinput
Use a folder that your project owns and that is not one of your source folders. Two mistakes cause the next error in line:
- Don't point
STATIC_ROOTat a folder inSTATICFILES_DIRS. Django stops withImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting. Keep your hand-written files in something likestatic/and the collected output instaticfiles/. - Don't commit
staticfiles/. Add it to.gitignoreand generate it in every build.
Then make something serve the folder. The simplest option is WhiteNoise, covered step by step in the static files guide.
Making it stick in production
- Run
collectstaticas part of the build, right after your code is copied in, so it uses the same settings module as the running app. - If your settings need secrets just to import, set a throwaway value for that one command:
SECRET_KEY=build-only python manage.py collectstatic --noinput. - Confirm which settings file a command uses with
python manage.py diffsettings | grep STATIC_ROOT. - Run
python manage.py check --deploybefore each release (deployment checklist).
Or skip it
Django Cloud runs collectstatic during every build and serves the result with WhiteNoise, unless your settings already serve static files another way, so there is no STATIC_ROOT step to forget.
pip install djangocloud-cli
djangocloud deploy
Free plans are available for students, AWS Activate startups, open-source, non-profit and research projects. See how Django Cloud compares with other ways to host Django.
Django is a registered trademark of the Django Software Foundation. Django Cloud is not affiliated with or endorsed by it. Found a mistake in this guide? Tell us and we will fix it.