How to make Django serve static files with Gunicorn?

When in development mode and when you are using some other server for local development add this to your urls.py

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

# ... the rest of your URLconf goes here ...

urlpatterns += staticfiles_urlpatterns()

Note that staticfiles_urlpatterns() will only work when DEBUG = True is set in your settings.py.

More info here

When in production you never, ever put gunicorn in front. Instead you use
a server like nginx which dispatches requests to a pool of gunicorn workers and also serves the static files.

See here

Leave a Comment