Home >Backend Development >Python Tutorial >How to Extract Named Parameters from a URL in Flask Applications?
How to Retrieve Named Parameters from a URL in Flask Applications
When processing user requests in Flask, it is common to encounter URLs containing named parameters specified after a question mark. These parameters provide a means to pass data to the server. For instance, consider the URL:
http://example.com/login?username=alex&password=password123
To manipulate the parameters embedded in such URLs, Flask provides a convenient method called request.args.
Solution:
To fetch the parsed contents of the query string, use the following code:
<code class="python">from flask import request @app.route(...) def login(): username = request.args.get('username') password = request.args.get('password') # Perform desired operations based on username and password</code>
In this example, the get method is used to retrieve the values of the 'username' and 'password' parameters. The retrieved values can then be processed or stored as desired within the Flask application.
The above is the detailed content of How to Extract Named Parameters from a URL in Flask Applications?. For more information, please follow other related articles on the PHP Chinese website!