第一步:安装flask:pip install flask (本文只需flask)
第二步:编写程序
from flask import abort, jsonify, Flask, request, Response app = Flask(__name__) # 增加配置,支持中文显示 app.config['JSON_AS_ASCII'] = False
taskss = { "code": 0, "msg": "OK", "data": { "waybillNumber": "1526351", "serviceMode": "10", "waybillStatus": "10", "deliveryAbbreviationAddress": "深圳", "pickupAbbreviationAddress": "深圳" }, "traceId": "dp1r" }
tasksl = { "code": 0, "data": { "waybillStatus": "10", "deliveryAbbreviationAddress": "深圳", }, }
@app.route('/task/ss', methods=['GET','POST']) #访问网址:http://127.0.0.1:6868/task/ss def get_taskss(): return jsonify(taskss)
@app.route('/task/sl', methods=['GET','POST']) #访问网址:http://127.0.0.1:6868/task/sl
def get_tasksl():
return jsonify(tasksl)
if __name__ == '__main__':
app.run(host = '0.0.0.0',port = 6868,debug = True)
第三步:网址验证:
(1)、http://127.0.0.1:6868/task/ss
(2)、http://127.0.0.1:6868/task/sl
第四部:postman验证: