The package comes with support for routing URLs to skin objects. This works with resources – images, stylesheets and other static files – and templates (these are rendered into a response).
For Pyramid to render the skin objects, we must register views such that the router can publish them. The benefit is that we can reuse the view directive and even protect the views with permissions.
To expose the contents of a skin directory as views, we can insert a view registration directive into the skins directive:
<skins path="skins">
<view />
</skins>
The view directive has no required attributes, but all the attributes which are applicable for the standalone directive [1] are available, except name which is defined by the component and view which is given by the skin object.
Note
Views are registered using the component name. However, the directory separator character (“/”) is replaced by an underscore (e.g. “images/logo.png” becomes “images_logo.png”). This is a technical detail if you use the built-in routing functionality.
When wrapped inside skins, an option index is available to allow registering default index views (e.g. index.pt):
<skins path="skins">
<view index="index.pt" />
</skins>
When an index name is set, a view is registered for the directory path, mapped to the index object in the directory.
[1] | See the Pyramid view predicate documentation for more information on view predicates and request types. |
We can configure a route to serve up skins registered as views under some path – subpath – using the provided routes traverser factory:
<route
name="skins"
path="/static/*subpath"
factory="pyramid_skins.RoutesTraverserFactory"
use_global_views="True"
/>
This traverser will convert subpath into a view name which then prompts the Pyramid router to publish the skin object (by calling it).