skip to navigation
skip to content

repoze.bfg.static 0.7

Static resource serving across WSGI application.

Overview

repoze.bfg.static provides a single point of entry to serving static resources across a WSGI application.

Register one or more directories where static resources are located and use the utility functions to get a URL to a resource given the full file-system path.

Documentation

Setting up a new static directory is a single adapter registration:

>>> from repoze.bfg.static import static_view_factory
>>> component.provideAdapter(
...     static_view_factory(static_path), name='static')

Given a request (we've prepared a test-request already), we can now get a URL to the resource.

>>> from repoze.bfg.static import get_url
>>> get_url(object(), test_request, static_path)
u'http://host/static/'

A skin template API is available for templates to retrieve a URL for a resource local to it.

In a skin template, you would use an expression like the following:

<img src="${template.get_url('image.png')}" />

In python-code, this is what happens under the hood:

>>> from repoze.bfg.skins.interfaces import ISkinTemplate
>>> class mock_template:
...     interface.implements(ISkinTemplate)
...
...     path = static_path
>>> from repoze.bfg.skins.interfaces import ISkinApi
>>> get_url = component.getMultiAdapter(
...     (object(), test_request, mock_template()),
...     ISkinApi, 'static_url')
>>> get_url("image.png")
u'http://host/static/image.png'
File Type Py Version Uploaded on Size # downloads
repoze.bfg.static-0.7.tar.gz (md5) Source 2009-02-12 14:32:31.483234 5KB 129

Log in to rate this package.