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:

  • 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):
        self.render("mytemplate.html")


if __name__ == "__main__":
    application = tornado.web.Application(
        [
            (r"/", MyHandler),
            (r"/xstatic/(.*)", XStaticFileHandler,
                {"allowed_modules": ["jquery", "bootstrap"]}),
        ],
        ui_methods={'xstatic_url': xstatic_url('/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_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.

Source Distribution

tornado_xstatic-0.3.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tornado_xstatic-0.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tornado_xstatic-0.3.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.0

File hashes

Hashes for tornado_xstatic-0.3.tar.gz
Algorithm Hash digest
SHA256 c1dea4f690886c563d4be9baf03cc0eeb548eb0648436872d8365cf02edd9f2a
MD5 42b941df4e4deecd3bcb559a78559e8f
BLAKE2b-256 8d85368b4f9ad0708e9a56a35903d5fbd43473dc1f69bab7bbbe342f3808adb4

See more details on using hashes here.

File details

Details for the file tornado_xstatic-0.3-py3-none-any.whl.

File metadata

  • Download URL: tornado_xstatic-0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.27.0

File hashes

Hashes for tornado_xstatic-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 29aac34f77105275a9dcf75ef7ee7ead0458596758fc63bbc0f256a33b5ab15a
MD5 5edfe63e61ed60c29c145141d821a457
BLAKE2b-256 6774b3c035bc1c0cf05ebf4c2c783426de0f8a325a02690e4a9148bf58a5d777

See more details on using hashes here.

Supported by

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