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

前端 未结 2 1877
误落风尘
误落风尘 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: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
    

提交回复
热议问题