Categories
Python Answers

How to access the query string in Python Flask routes?

Spread the love

Sometimes, we want to access the query string in Python Flask routes.

In this article, we’ll look at how to access the query string in Python Flask routes.

How to access the query string in Python Flask routes?

To access the query string in Python Flask routes, we can use the request.args property.

For instance, we write

from flask import request

@app.route('/login')
def login():
    username = request.args.get('username')
    password = request.args.get('password')

to call request.args.get with the keys of the query parameters we want to get in our view function.

Conclusion

To access the query string in Python Flask routes, we can use the request.args property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *