Flask結合Postman驗證request請求上下文
阿新 • • 發佈:2018-12-13
- 注意: 使用的時候修改Postman前邊的get與post請求 清理headers中的資料
示例一
@app.route("/index", methods=["GET"])
def index():
city = request.args.get("city")
country = request.args.get("country")
return "city=%s, country=%s" % (city, country)
示例二 @app.route("/index/post1", methods=["POST"]) def index_post1(): name = request.form.get("name") age = request.form.get("age") multi = request.form.getlist("multi") return "name=%s, age=%s, multi=%s" % (name, age, multi)
示例三
@app.route("/index/post2", methods=["POST"])
def index_post2():
print("request.data: %s" % request.data)
return "request.data=%s" % request.data.decode("utf8")
示例四 @app.route("/upload", methods=["POST"]) def upload(): file_obj = request.files.get("pic") if file_obj is None: return "未上傳任何檔案" file_obj.save("./demo.png") return "上傳成功"