__main__.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import tornado.ioloop
  2. import tornado.web
  3. from demos.bmi import main as bmi
  4. from demos.chat_room import main as chat_room
  5. from demos.input_usage import main as input_usage
  6. from demos.output_usage import main as output_usage
  7. from pywebio import STATIC_PATH
  8. from pywebio.output import put_markdown
  9. from pywebio.platform.tornado import webio_handler
  10. from tornado.options import define, options
  11. index_md = r"""# PyWebIO demos
  12. ### Demos list
  13. * [BMI计算](./?pywebio_api=bmi): 根据身高体重计算BMI指数
  14. * [聊天室](./?pywebio_api=chat_room): 和当前所有在线的人聊天
  15. * [输入演示](./?pywebio_api=input_usage): 演示PyWebIO输入模块的用法
  16. * [输出演示](./?pywebio_api=output_usage): 演示PyWebIO输出模块的用法
  17. ### Links
  18. * PyWebIO Github [github.com/wang0618/PyWebIO](https://github.com/wang0618/PyWebIO)
  19. * 使用手册和开发文档见 [pywebio.readthedocs.io](https://pywebio.readthedocs.io)
  20. """
  21. def index():
  22. put_markdown(index_md)
  23. if __name__ == "__main__":
  24. define("port", default=5000, help="run on the given port", type=int)
  25. tornado.options.parse_command_line()
  26. application = tornado.web.Application([
  27. (r"/io", webio_handler(index)),
  28. (r"/bmi", webio_handler(bmi)),
  29. (r"/chat_room", webio_handler(chat_room)),
  30. (r"/input_usage", webio_handler(input_usage)),
  31. (r"/output_usage", webio_handler(output_usage)),
  32. (r"/(.*)", tornado.web.StaticFileHandler, {"path": STATIC_PATH, 'default_filename': 'index.html'})
  33. ])
  34. application.listen(port=options.port)
  35. tornado.ioloop.IOLoop.current().start()