Django Collectstatic Command
The collectstatic
command in Django is used to gather all static files from your applications and any other locations specified in your settings into a single directory, typically for deployment purposes.
The goal is to collect all static files into a single directory, which can then be served by a web server in production.
In my case we use MinIO to serve static files, so we put the urls of this minio bucket in the STATIC_URL
setting.
Basic Usage
python -m manage collectstatic
Don't forget to ignore the staticfiles
directory in your .gitignore
echo "staticfiles/" >> .gitignore
Settings
settings.py
should include the following configurations:
STATIC_URL = 'https://<minion_server>:9000/django-staticfiles/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
Additional Options to update the static files
You can pass additional options to the collectstatic
command:
python -m manage collectstatic --noinput --clear
This command will run without prompting for input and will clear the existing static files in the STATIC_ROOT
directory before collecting new ones.