Categories
Python Answers

How to get the named parameters from a URL using Python Flask?

Spread the love

Sometimes, we want to get the named parameters from a URL using Python Flask

In this article, we’ll look at how to get the named parameters from a URL using Python Flask.

How to get the named parameters from a URL using Python Flask?

To get the named parameters from a URL using Python Flask, 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 get the named parameters from a URL using Python Flask, 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 *