If you want to host your Pyramid static files in s3 or compile everything to a local folder, just like Django's collectstatic, van.static is to the rescue.
Before going further, ensure that all of your statics are resolved from the request object and any references from CSSs use relative paths. A Mako example would be: ${request.static_url("app:static/image.png")}.
Install van.static to your virtual environment with pip install van.static.
Setup van.static in your app's entry point:
from van.static import cdn
static_resources = (('static', 'app:static'),)
cdn.config_static(config,
static_resources,
static_cdn=settings.get("static_cdn"))
If you want to collect all static files together:
python -m van.static.cdn --target=file:///srv/static/myapp/ --resource="app:static"
van.static has 2 modes:
- Development mode
- If you do not provide it a static_cdn parameter, it serves everything via Pyramid's static view.
- Production mode
- If you provide the parameter, it simply generates unique urls for each version of your application, prefixing the given URL.
The software is not even a month old but already can compress files with YUI compressor and seems to be pretty usable.
0 comments:
Post a Comment