beginner's question:
is it possible to pass GET request parameters to a route function in Flask using add_url_rule
?
I am getting the error message that the verify_username_route
function I declare later (that takes 1 parameter) is called without any parameters passed.
self.application_.add_url_rule(self.path_ '/verify', 'verify', self.verify_username_route, methods=['GET'])
CodePudding user response:
To fetch query string parameters, you use request.args.get('argname')
in your function. Nothing is passed in -- it's all done through the globals.
CodePudding user response:
To pass any parameters in your URLs, you can use Flask's built-in patterns. These work for both @app.route
decorators and add_url_route
methods. Here is your code, with a parameter:
self.application_.add_url_rule(self.path_ '/verify/<int:val>', 'verify', self.verify_username_route, methods=['GET'])
The important part from this is the exact route: /verify/<int:parameter>
. This tells Flask that you want the route to be in the format of /verify/something
, where something is any integer. Whatever integer is entered here when the request is made gets passed to your self.verify_username_route
as a parameter called val
.
Read more about this here.