How to make Django serve static files with Gunicorn?


I want to run my django project under gunicorn on localhost. I installed and integrated gunicorn. When I run:

python run_gunicorn

It works but there are no any static files (css and js)

I disabled debug and template_debug in (made them false), but it is still same. Am I missing something?

I call statics like:

{{ STATIC_URL }}css/etc....
9/6/2018 11:38:31 AM

Accepted Answer

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

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

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

urlpatterns += staticfiles_urlpatterns()

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

10/9/2012 1:45:29 PM


Post v4.0

The WSGI integration option for Django (which involved editing has been removed. Instead, you should add WhiteNoise to your middleware list in and remove any reference to WhiteNoise from See the documentation for more details. (The pure WSGI integration is still available for non-Django apps.)

Pre v4.0

Heroku recommends this method at:

Your application will now serve static assets directly from Gunicorn in production. This will be perfectly adequate for most applications, but top-tier applications may want to explore using a CDN with Django-Storages.

Install with:

pip install whitenoise
pip freeze > requirements.txt

import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "free_books.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)

Tested on Django 1.9.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow