标签:turn height out rom err else deb route span
一、GET和POST请求
from flask import Flask,jsonify
data = {
‘name‘:‘Jerry‘,
‘sex‘:‘男‘,
‘age‘:‘18‘
}
app = Flask(__name__)
@app.route(‘/get_user‘,methods=[‘Get‘,‘post‘])
def get_user():
return jsonify(data)
app.run(host=‘0.0.0.0‘,port=8888,debug=True)
二、POST三种传参方式
1. k-v传参
2. url传参
3. json传参
from flask import Flask,jsonify,request
data = {
‘Jerry‘:{‘sex‘:‘男‘,‘age‘:18},
‘Tom‘:{‘sex‘:‘男‘,‘age‘:20},
}
app = Flask(__name__)
@app.route(‘/get_user‘,methods=[‘post‘])
def get_user():
# username = request.form[‘username‘]#key-value传参
# username = request.args.get(‘username‘)#?+url传参
username = request.json.get(‘username‘)#json传参
if username in data:
return jsonify(data[username])
else:
return jsonify(500)
app.run(host=‘0.0.0.0‘,port=8888,debug=True)
标签:turn height out rom err else deb route span
原文地址:http://www.cnblogs.com/leilei0111/p/6234851.html