Request Params And Request Body

  • GET

    When get query params, you will get tuples, first value is key, second is value

    from flask import request
     
     
    @app.route('/')
    def home():
        print(request.args)
        return "<h1>hello world</h1>" 

    image 15.png

  • Post

    Also will convert to tuples, first value is key, second is value.

    Content-Type is not json then you can’t use request.json

    @app.route('/post-test', methods=['POST'])
    def post_test():
        print(request.form)
        # print(request.json)
        return "<h1>hello world</h1>"
  • args.get

    Maybe you can use args.get to get request params, no matter it’s from get params or post body.

@app.route('/')
def home():
    name = request.args.get('name')
    return "<h1>hello world</h1>"