# -*- coding: UTF-8 -*-
# !/usr/bin/python
# @time :2019/10/12 11:11
# @author :Mo
# @function :service of flask
from flask import Flask, request, jsonify
app = Flask(__name__)
g_a = 100
g_b = 200
g_c = 300
@app.route('/add', methods=["GET"])
def calculate():
if request.method == 'GET':
params = request.args
else:
params = request.form if request.form else request.json
a = params.get("a", 0)
b = params.get("b", 0)
c = int(a) + int(b)+100
res = {"result": c}
return jsonify(content_type='application/json;charset=utf-8',
reason='success',
charset='utf-8',
status='200',
产能 = str(g_a),
总产量 = str(g_b),
异常 = str(g_c),
content=res)
@app.route('/add1', methods=["POST"])
def calculate1():
global g_a
global g_b
global g_c
if request.method == 'POST':
params = request.args
else:
params = request.form if request.form else request.json
g_a = params.get("a", 0)
g_b = params.get("b", 0)
g_c = params.get("c", 0)
c = int(g_a) + int(g_b)
res = {"result": c}
return jsonify(content_type='application/json;charset=utf-8',
reason='success',
charset='utf-8',
status='200',
content=res)
if __name__ == '__main__':
print('start')
app.run(host='0.0.0.0',
threaded=True,
debug=False,
port=8868)
python flask httpserver
最新推荐文章于 2024-07-25 13:14:25 发布