1 # -*- coding: utf-8 -*- 2 3 # 从前端传过来的数据,统一交给request对象处理 4 from flask import request 5 6 def get_param_get_or_post(*keys): 7 ret = [] 8 print("parm is:{}".format(keys)) 9 # 前端传进来的几种方式,将参数解析后放到对应的列表中 10 for key in keys: 11 if request.json: 12 ret.append(request.json.get(key)) 13 elif request.method == "GET": 14 ret.append(request.args.get(key, None)) 15 elif request.method == "POST": 16 ret.append(request.form.get(key, None)) 17 print("ret is:{}".format(ret)) 18 # 方便位置取参 19 if len(ret) == 1 and ret[0] == None: 20 return ret[0] 21 else: 22 return ret