flask restful: passing parameters to GET request

后端 未结 3 611
不知归路
不知归路 2020-12-13 23:30

I want to create a resource that supports GET request in following way:

/bar?key1=val1&key2=val2

I tried this code, but it is not worki

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 00:24

    Flask can parse arguments through request

    from flask import request
    

    You can use following lines in the block that requires GET parameters. GET is declared in @app.route() declaration.

    args = request.args
    print (args) # For debugging
    no1 = args['key1']
    no2 = args['key2']
    return jsonify(dict(data=[no1, no2])) # or whatever is required
    

提交回复
热议问题