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)}) # 返回布尔值

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐