from flask import request @app.route('/data') def data(): # here we want to get the value of user (i.e. ?user=some-value) user = request.args.get('user')
Here is what the above code is Doing:
1. We’re using the @app.route decorator to tell Flask what URL should trigger our function.
2. The function is given a name which is also used to generate URLs for that particular function, and returns the message we want to display in the user’s browser.
3. We imported request from the flask package. This is the object that flask will use to look at the incoming request.
4. We use the request.args.get() method to get the value of the user parameter.
5. We put the value of user into the string that we’re going to return.