Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takluyver/tornado_xstatic
Utilities for using XStatic in Tornado applications
https://github.com/takluyver/tornado_xstatic
Last synced: 14 days ago
JSON representation
Utilities for using XStatic in Tornado applications
- Host: GitHub
- URL: https://github.com/takluyver/tornado_xstatic
- Owner: takluyver
- License: bsd-3-clause
- Created: 2014-09-29T17:46:06.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-05-05T08:36:56.000Z (over 2 years ago)
- Last Synced: 2024-12-27T22:56:27.803Z (16 days ago)
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Utilities for using XStatic in Tornado applications
---------------------------------------------------`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:
.. code:: python
import tornado.ioloop
import tornado.web
from tornado_xstatic import XStaticFileHandler, xstatic_urlclass 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::