dj-static python

Serve production static files with Django.

3 years after


This is a simple Django middleware utility that allows you to properly serve static assets from production with a WSGI server like Gunicorn.

Django doesn't recommend <> the production use of its static file server for a number of reasons. There exists, however, a lovely WSGI application aptly named Static <>.

.. image::

"Finally, a super-simple way of serving assets in Django that’ll actually perform well" — @jacobian <>_

It is suitable for the production use of static file serving, unlike Django. Enjoy!

Shouldn't I use a CDN?

If you have to ask that question, there's actually quite a good chance you don't. Static responses aren't very different than dynamic ones.

If you're running a top-tier application, optimizing for delivery and reducing frontend load, you will want to explore using a CDN with Django-Storages <>_.



$ pip install dj-static

Configure your static assets in

STATIC_ROOT = 'staticfiles' STATIC_URL = '/static/'

Then, update your file to use dj-static::

from django.core.wsgi import get_wsgi_application
from dj_static import Cling

application = Cling(get_wsgi_application())

File uploads (optional) ^^^^^^^^^^^^^^^^^^^^^^^

In case you also want to serve media files that were uploaded to MEDIA_ROOT::

MEDIA_ROOT = 'media'
MEDIA_URL = '/media/'

Then again, update your file::

from django.core.wsgi import get_wsgi_application
from dj_static import Cling, MediaCling

application = Cling(MediaCling(get_wsgi_application()))

Related Repositories



A set of utilities and a project template for running Django sites on Heroku. ...



Heavily personalized fork of the project template from "Two Scoops of Django 1.6 ...



A skeleton Django project ...



Adds easy python 3 and 2.7 support to Django for management of static assets. ...




Top Contributors

kennethreitz agriffis axelmagn jezdez tinnet andrewsg gone Roadmaster metakermit gciding goldibex kwilcox stefanw treyhunner wking wnh maria


-   v0.0.6 zip tar