Flask结合Postman验证request请求上下文

  • 注意:
    使用的时候修改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 "上传成功"


猜你喜欢

转载自blog.csdn.net/iehadoop/article/details/82952664