python flask httpserver

# -*- 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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值