Utilities for using XStatic in Tornado applications
Project description
XStatic is a means of packaging static files, especially JS libraries, for Python applications. Tornado is a Python web framework.
This integration provides two pieces:
XStaticFileHandler to serve static files from XStatic packages.
url_maker to build URLs for XStatic files, including the ?v=... tag that Tornado uses for cache invalidation.
To use these:
import tornado.ioloop
import tornado.web
import tornado_xstatic
class MyHandler(tornado.web.RequestHandler):
def get(self):
self.render("mytemplate.html",
xstatic=self.application.settings['xstatic_url'])
if __name__ == "__main__":
application = tornado.web.Application([
(r"/", MyHandler),
(r"/xstatic/(.*)", tornado_xstatic.XStaticFileHandler,
{"allowed_modules": ["jquery"]}),
], xstatic_url=tornado_xstatic.url_maker("/xstatic/")
)
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
Passing allowed_modules is optional: if it is not provided, files from any XStatic module may be served.
In your template, you can then do this:
<script src="{{ xstatic('jquery', 'jquery.min.js') }}"></script>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
tornado_xstatic-0.1.tar.gz
(2.4 kB
view hashes)