Skip to main content

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


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 details)

Uploaded Source

File details

Details for the file tornado_xstatic-0.1.tar.gz.

File metadata

File hashes

Hashes for tornado_xstatic-0.1.tar.gz
Algorithm Hash digest
SHA256 f41cff3b5884372f63d28b6887df3d29dce0fb44e1ce31c8996d626ff8b72015
MD5 22107ce3bbcc0439636885f248df63cf
BLAKE2b-256 e5e31614610f24bf276930f6e6eb5b9bfc17e51efd202b591d1b5e58a880c838

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page