While you're able to use Django to serve static files in development mode with the app django.contrib.staticfiles
, that is not suitable for production use.
In order to serve static files, as Jamie Hewland says, normally one routes all the requests to /static/ using Nginx
location /static/ {
alias /path/to/static/files;
}

Also, and as coreyward says about Gunicorn / Unicorn
was not designed to solve the suite of problems involved in serving
files to clients
Same line of reasoning applies if you consider other WSGI server like uWSGI instead of Gunicorn. In uWSGI documentation
it’s inefficient to serve static files via uWSGI. Instead, serve them
directly from Nginx and completely bypass uWSGI
So, serving static files in production is something to be done by NGINX, not by Django or other WSGI servers.
Another way is to serve your static files in production is using WhiteNoise library which is very easy to setup (you might want to use a CDN so that most requests won't reach the Python app). As Miguel de Matos says, you just have to
Collect static
python manage.py collectstatic
Installing whitenoise
pip install whitenoise
Add the following STATICFILES_STORAGE
in settings.py
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
Add the following to your MIDDLEWARE
in settings.py (as mracette notes, "According to the whitenoise docs you should place the middleware after django.middleware.security.SecurityMiddleware
")
`MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]