Skip to content

Quick Start

The documentation below is a quick-start guide to using ServeStatic to serve your static files. For more detailed information see the full installation docs.


Installation

Install with:

pip install servestatic

Using with Django

Edit your settings.py file and add ServeStatic to the MIDDLEWARE list, above all other middleware apart from Django's SecurityMiddleware.

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "servestatic.middleware.ServeStaticMiddleware",
    # ...
]

That's it, you're ready to go.

Want forever-cacheable files and compression support? Just add this to your settings.py.

STORAGES = {
    "staticfiles": {
        "BACKEND": "servestatic.storage.CompressedManifestStaticFilesStorage",
    },
}

For more details, including on setting up CloudFront and other CDNs see the full Django guide.

Using with WSGI

To enable ServeStatic you need to wrap your existing WSGI application in a ServeStatic instance and tell it where to find your static files. For example...

1
2
3
4
5
6
7
from servestatic import ServeStatic

from my_project import MyWSGIApp

application = MyWSGIApp()
application = ServeStatic(application, root="/path/to/static/files")
application.add_files("/path/to/more/static/files", prefix="more-files/")

And that's it, you're ready to go. For more details see the full WSGI guide.

Using with ASGI

To enable ServeStatic you need to wrap your existing ASGI application in a ServeStatic instance and tell it where to find your static files. For example...

1
2
3
4
5
6
7
from servestatic import ServeStaticASGI

from my_project import MyASGIApp

application = MyASGIApp()
application = ServeStaticASGI(application, root="/path/to/static/files")
application.add_files("/path/to/more/static/files", prefix="more-files/")

And that's it, you're ready to go. For more details see the full ASGI guide.