|
发表于 2020-11-16 11:14:50
|
显示全部楼层
浙江省宁波市
- #!/usr/bin/env python
- # coding:utf-8
- import json
- import tornado.httpserver
- import tornado.ioloop
- import tornado.web
- import tornado.web
- from tornado.options import define, options
- import test
- define("port", default=81, help="run on the given port", type=int)
- class IndexHandler(tornado.web.RequestHandler):
- def get(self):
- data = str(test.run(self.get_query_argument('e'))) #获取get参数 ‘e’
- self.set_header("Content-Type", "application/json") #返回协议后,可累加
- self.write(str(json.dumps(data))) 响应数据
- if __name__ == "__main__":
- tornado.options.parse_command_line()
- app = tornado.web.Application(handlers=[(r"/", IndexHandler)])
- http_server = tornado.httpserver.HTTPServer(app)
- http_server.listen(options.port)
- tornado.ioloop.IOLoop.instance().start()
复制代码
|
|