Flask 中接收与发送json 方式详解
一、Flask中json数据的接收1、利用flask的request.form.get()方法from flask import Flaskfrom flask import jsonifyfrom flask import requestimport json@app.route("/login", methods=['POST'])def login():d
·
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)}) # 返回布尔值
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献1条内容
所有评论(0)