Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

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:

  • XStaticFileHandler to serve static files from XStatic packages.
  • xstatic_url ui method 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
from tornado_xstatic import XStaticFileHandler, xstatic_url

class MyHandler(tornado.web.RequestHandler):
    def get(self):

if __name__ == "__main__":
    application = tornado.web.Application(
            (r"/", MyHandler),
            (r"/xstatic/(.*)", XStaticFileHandler,
                {"allowed_modules": ["jquery", "bootstrap"]}),
        ui_methods={'xstatic_url': xstatic_url('/xstatic/')}

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_url('jquery', 'jquery.min.js') }}"></script>
<script src="{{ xstatic_url('bootstrap', 'js/bootstrap.min.js') }}"></script>

<link href="{{ xstatic_url('bootstrap', 'css/bootstrap.min.css') }}" rel="stylesheet">

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tornado_xstatic, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size tornado_xstatic-0.2-py2.py3-none-any.whl (3.0 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page