下面来说一下Flask中接收与发送json方式
1、利用flask的request.form.get()方法接收
from flask import Flask from flask import jsonify from flask import request import json @app.route("/login", methods=['POST']) def login(): data_ = request.form.get('data') data = json.loads(data) username = data['username'] password = data['password'] return jsonify({"login": Login.login(username, password)}) # 返回布尔值
2、 利用flask的request.get_data()方法接收
from flask import Flask from flask import jsonify from flask import request import json @app.route("/flask/login", methods=['POST']) def login(): data = request.get_data() data = json.loads(data) username = data['username'] password = data['password'] return jsonify({"login": Login.login(username, password)}) # 返回布尔值
3、利用flask的request.get_json()方法接收
from flask import Flask from flask import jsonify from flask import request @app.route("/flask/login", methods=['POST']) def login(): data = request.get_json() username = data['username'] password = data['password'] return jsonify({"login": Login.login(username, password)}) # 返回布尔值
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试