0

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'])
0

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.