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
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file tornado_xstatic-0.2-py2.py3-none-any.whl
.
File metadata
- Download URL: tornado_xstatic-0.2-py2.py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b542e2e4edb959bef5ef69b17b133460bda97df8d05b9490beb6a0cfc63faa94 |
|
MD5 | 7cf83908247c90c5bb48a5245b1fa29b |
|
BLAKE2b-256 | 3f5d51ce8394499f331bd4a9717d9667559aabe6315fcaa0307c4c11555577f0 |