tornoda 相关资料

1. 
from tornado.web import Application, RequestHandler
from tornado.ioloop import IOLoop
import json

class IndexHandler(RequestHandler):
    def get(self):
        print (self.request)

        json_str = {"username": "admin", "password": "123123"}
        self.write(json.dumps(json_str))



if __name__ == "__main__":
    app = Application([(r"/", IndexHandler)])

    app.listen(8000)

    IOLoop.current().start()
在浏览器输入127.0.0.1得到结果

{"username": "admin", "password": "123123"}

2. tornado 接收post请求,发送json内容 实现代码如下:

# -*- coding:utf-8 -*-

from tornado.web import Application, RequestHandler
from tornado.ioloop import IOLoop
from tornado.escape import json_decode

class IndexHandler(RequestHandler):
    def post(self,*args,**kwargs):
        data=json_decode(self.request.body)
        self.write(data)
if __name__ == "__main__":
    app = Application([(r"/", IndexHandler)])
    app.listen(8000)
    IOLoop.current().start()

默认的ip:port 为127.0.0.1:8000

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页