python使用tornado开发Web服务器

妖狐艹你老母 2023-02-17 03:11 66阅读 0赞

代码

  1. #-*- coding:utf-8 -*-
  2. import tornado.web
  3. import tornado.ioloop
  4. import tornado.httpserver
  5. import tornado.options
  6. from tornado.options import define, options
  7. from mm import mm
  8. define('port', type=int, default=8000, help='服务器端口')
  9. # 定义接口
  10. class into_Handler(tornado.web.RequestHandler):
  11. def get(self):
  12. # 接收参数
  13. arg1 = self.get_query_argument('csvdatapath', '')
  14. arg2 = self.get_query_argument('modelpath', '')
  15. try:
  16. obj = mm()
  17. obj.into(arg1,arg2)
  18. except:
  19. self.write("failed")
  20. finally:
  21. # 给客户端返回值
  22. self.write("success")
  23. if __name__ == '__main__':
  24. tornado.options.parse_command_line()
  25. static_path = ""
  26. app = tornado.web.Application([
  27. # 路由配置
  28. ('/into', into_Handler),
  29. ],
  30. static_path=os.path.join(os.path.dirname(__file__), "statics"),
  31. dubug=True
  32. )
  33. http_server = tornado.httpserver.HTTPServer(app)
  34. http_server.listen(options.port)
  35. tornado.ioloop.IOLoop.current().start()

结果

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,66人围观)

还没有评论,来说两句吧...

相关阅读