Documentation in progress Edit me on GitHub

pyramid.static

class static_view(root_dir, cache_max_age=3600, package_name=None, use_subpath=False, index='index.html', cachebust_match=None)[source]

An instance of this class is a callable which can act as a Pyramid view callable; this view will serve static files from a directory on disk based on the root_dir you provide to its constructor.

The directory may contain subdirectories (recursively); the static view implementation will descend into these directories as necessary based on the components of the URL in order to resolve a path into a response.

You may pass an absolute or relative filesystem path or a asset specification representing the directory containing static files as the root_dir argument to this class' constructor.

If the root_dir path is relative, and the package_name argument is None, root_dir will be considered relative to the directory in which the Python file which calls static resides. If the package_name name argument is provided, and a relative root_dir is provided, the root_dir will be considered relative to the Python package specified by package_name (a dotted path to a Python package).

cache_max_age influences the Expires and Max-Age response headers returned by the view (default is 3600 seconds or one hour).

use_subpath influences whether request.subpath will be used as PATH_INFO when calling the underlying WSGI application which actually serves the static files. If it is True, the static application will consider request.subpath as PATH_INFO input. If it is False, the static application will consider request.environ[PATH_INFO] as PATH_INFO input. By default, this is False.

Note

If the root_dir is relative to a package, or is a asset specification the Pyramid pyramid.config.Configurator method can be used to override assets within the named root_dir package-relative directory. However, if the root_dir is absolute, configuration will not be able to override the assets it contains.

class PathSegmentMd5CacheBuster[source]

An implementation of ICacheBuster which inserts an md5 checksum token for cache busting in the path portion of an asset URL. Generated md5 checksums are cached in order to speed up subsequent calls.

New in version 1.6.

class QueryStringMd5CacheBuster(param='x')[source]

An implementation of ICacheBuster which adds an md5 checksum token for cache busting in the query string of an asset URL. Generated md5 checksums are cached in order to speed up subsequent calls.

The optional param argument determines the name of the parameter added to the query string and defaults to 'x'.

New in version 1.6.

class QueryStringConstantCacheBuster(token, param='x')[source]

An implementation of ICacheBuster which adds an arbitrary token for cache busting in the query string of an asset URL.

The token parameter is the token string to use for cache busting and will be the same for every request.

The optional param argument determines the name of the parameter added to the query string and defaults to 'x'.

New in version 1.6.

Previous topic

pyramid.settings

Next topic

pyramid.testing