python使用tornado开发Web服务器

代码

#-*- coding:utf-8 -*-
import tornado.web
import tornado.ioloop
import tornado.httpserver
import tornado.options
from tornado.options import define, options

from mm import mm

define('port', type=int, default=8000, help='服务器端口')

# 定义接口
class into_Handler(tornado.web.RequestHandler):
    def get(self):
    	# 接收参数
        arg1 = self.get_query_argument('csvdatapath', '')
        arg2 = self.get_query_argument('modelpath', '')
        try:
            obj = mm()
            obj.into(arg1,arg2)
        except:
            self.write("failed")
        finally:
        	# 给客户端返回值
            self.write("success")



if __name__ == '__main__':
    tornado.options.parse_command_line()
    static_path = ""
    app = tornado.web.Application([
    	# 路由配置
        ('/into', into_Handler),
    ],
     static_path=os.path.join(os.path.dirname(__file__), "statics"),
     dubug=True
    )
    
http_server = tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.current().start()

结果

python使用tornado开发Web服务器_第1张图片

你可能感兴趣的:(python,tornado,python服务器,python开发web服务器,tornado路由配置,tornado框架)