How to obtain values of parameters of get request in flask?

前端 未结 2 1868
误落风尘
误落风尘 2020-12-15 14:48

The answer that I found on the web is to use request.args.get. However, I cannot manage it to work. I have the following simple example:

from fl         


        
相关标签:
2条回答
  • 2020-12-15 15:28

    http://localhost:5000/api/iterators/opel/next?n=5

    For something like the case before

    from flask import Flask, request
    n = request.args.get("n")
    

    Can do the trick

    0 讨论(0)
  • 2020-12-15 15:39

    The simple answer is you have not imported the request global object from the flask package.

    from flask import Flask, request
    

    This is easy to determine yourself by running the development server in debug mode by doing

    app.run(debug=True)
    

    This will give you a stacktrace including:

    print request.args['x']
    NameError: global name 'request' is not defined
    
    0 讨论(0)
提交回复
热议问题