一,flask构造post请求,参数是form格式 示例代码如下:
from flask import Flask
from flask import jsonify
from flask import request
app = Flask(__name__)
users_list = {"1001":["123","张三",19],
"1002":["234","李四",22],
"1003":["345","王二小",8]}
@app.route("/users",methods=["GET"])
def users():
return jsonify({"code":10000,"message":"success","data":users_list})
@app.route("/login",methods=["POST"])
def login():
account = request.form.get("account")
password = request.form.get("password")
if account and password:
if account in users_list:
info = users_list[account]
if password == info[0]:
return jsonify({"code":10000,"message":"success"})
else:
return jsonify({"code":10001,"message":"密码不正确"})
else:
return jsonify({"code":10002,"message":"用户不存在"})
else:
return jsonify({"code":10003,"message":"用户名或密码为空"})
if __name__ == '__main__':
app.config['JSON_AS_ASCII'] = False
app.run(host="0.0.0.0",port=8899,debug=True)
传输正确的参数,效果如下: 用户名或密码为空,效果如下;
|