pyramid.static
¶
-
class
static_view
(root_dir, cache_max_age=3600, package_name=None, use_subpath=False, index='index.html')[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 thepackage_name
argument isNone
,root_dir
will be considered relative to the directory in which the Python file which callsstatic
resides. If thepackage_name
name argument is provided, and a relativeroot_dir
is provided, theroot_dir
will be considered relative to the Python package specified bypackage_name
(a dotted path to a Python package).cache_max_age
influences theExpires
andMax-Age
response headers returned by the view (default is 3600 seconds or five minutes).use_subpath
influences whetherrequest.subpath
will be used asPATH_INFO
when calling the underlying WSGI application which actually serves the static files. If it isTrue
, the static application will considerrequest.subpath
asPATH_INFO
input. If it isFalse
, the static application will consider request.environ[PATH_INFO
] asPATH_INFO
input. By default, this isFalse
.Note
If the
root_dir
is relative to a package, or is a asset specification the Pyramidpyramid.config.Configurator
method can be used to override assets within the namedroot_dir
package-relative directory. However, if theroot_dir
is absolute, configuration will not be able to override the assets it contains.