Navigation

Middlewares wrap applications to dispatch between them or provide
additional request handling. Additionally to the middlewares documented
here, there is also the DebuggedApplication class that is
implemented as a WSGI middleware.

The contents of the folder ./shared will now be available on
http://example.com/shared/. This is pretty useful during development
because a standalone media server is not required. One can also mount
files on the root folder and still continue to use the application because
the shared data middleware forwards all unhandled requests to the
application, even if the requests are below one of the shared folders.

If pkg_resources is available you can also tell the middleware to serve
files from package data:

This will then serve the shared_files folder in the myapplication
Python package.

The optional disallow parameter can be a list of fnmatch()
rules for files that are not accessible from the web. If cache is set to
False no caching headers are sent.

Currently the middleware does not support non ASCII filenames. If the
encoding on the file system happens to be the encoding of the URI it may
work but this could also be by accident. We strongly suggest using ASCII
only file names for static files.

The middleware will guess the mimetype using the Python mimetype
module. If it’s unable to figure out the charset it will fall back
to fallback_mimetype.

Changed in version 0.5: The cache timeout is configurable now.

New in version 0.6: The fallback_mimetype parameter was added.

Parameters:

app – the application to wrap. If you don’t want to wrap an
application you can pass it NotFound.