The collectstatic command gathers all static files from your Django apps into one place. This makes it easy to serve them efficiently in production.
collectstatic for production in Django
python manage.py collectstatic
This command copies static files into the directory set by STATIC_ROOT in your settings.
You usually run this command once before deploying your site.
python manage.py collectstatic
python manage.py collectstatic --noinput
python manage.py collectstatic --clear
This example shows the minimal settings needed and the command to collect static files. After running, all static files from apps and STATICFILES_DIRS are copied to staticfiles folder.
# settings.py STATIC_URL = '/static/' STATIC_ROOT = BASE_DIR / 'staticfiles' # Terminal command python manage.py collectstatic # Output example # You will see lines like: # 127 static files copied to '/path/to/project/staticfiles'
Make sure STATIC_ROOT is set and points to a folder outside your app directories.
Do not serve static files with Django in production; use a web server instead.
Run collectstatic every time you change static files before deploying.
collectstatic gathers all static files into one folder for easy serving.
Run it before deploying your Django project to production.
Set STATIC_ROOT in settings to tell Django where to collect files.