flask post获取前端请求参数的三种方式总结
Jenrey 人气:0flask post获取前端请求参数方式
post请求python flask获取前端发来的参数有三种方式
1、放在params里面
from flask import request # params拿请求 data = {} for key in request.args: data[key] = request.args.get(key) file_type = data['file_type'] safety_check_command = data['safety_check_command'] remark = data['remark'] create_user = data['create_user'] weight = data['weight']
2、带附件的 form-data
注意:不带附件,前端服务器express+pm2可能出现问题。
from flask import request file_obj = request.files.get('excel') DeploymentID = request.form['DeploymentID'] # 获取DeploymentID environment = request.form['environment'] # 获取环境 project = request.form['project'] # 获取项目
3、json格式
from flask import request, json data = request.get_data() json_data = json.loads(data.decode("UTF-8")) DeploymentID = json_data.get("DeploymentID") Gitlab_URL = json_data.get("Gitlab_URL") basics_URL = json_data.get("basics_URL")
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
加载全部内容