Home >Backend Development >Python Tutorial >How do I access named parameters in Flask URLs?
Accessing Named Parameters in Flask URLs
In Flask, handling named parameters in a URL is essential for extracting key-value pairs from requests.
Scenario:
Consider a Flask endpoint for user login:
http://10.1.1.1:5000/login?username=alex&password=pw1
Objective:
Solution:
Flask provides a powerful tool, request.args, to access named parameters from the query string:
<code class="python">from flask import request @app.route('/login') def login(): username = request.args.get('username') password = request.args.get('password')</code>
Now, username and password hold the extracted parameter values.
Note:
The above is the detailed content of How do I access named parameters in Flask URLs?. For more information, please follow other related articles on the PHP Chinese website!