Skip to content

Instantly share code, notes, and snippets.

@reedobrien
Created January 10, 2011 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reedobrien/772424 to your computer and use it in GitHub Desktop.
Save reedobrien/772424 to your computer and use it in GitHub Desktop.
mcdonc's versioned static view from pylonshq
## from http://paste.ofcode.org/39mWESwBQbwasheLuuYjRUv
# framework
from pyramid.view import static
# five year expires time
static_view = static('static', cache_max_age=157680000)
version_match = re.compile(r'^r\d{1,19}$').match
# version number is "r" plus an intified timetime, e.g. r1234567890
def versioning_static_view(context, request):
# if the first element in the subpath is the version number, strip
# it out of the subpath (see views/api.py static_url)
subpath = request.subpath
if subpath and version_match(subpath[0]):
request.subpath = subpath[1:]
return static_view(context, request)
# appconfig
config.add_route('static', '/static*subpath', view=versioning_static_view)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment