Extracting Named Parameters from URLs in Flask
Suppose you have a URL like http://10.1.1.1:5000/login?username=alex&password=pw1 that you want your Flask app to handle. To access the parameters specified after the question mark, use request.args, not request.form.
<code class="python">from flask import request @app.route('/login', methods=['GET', 'POST']) def login(): username = request.args.get('username') password = request.args.get('password')</code>
This code retrieves the values of the username and password parameters, if they exist in the URL. You can then manipulate these parameters as needed in your Python script.
The above is the detailed content of How to Extract Named Parameters from URLs in Flask?. For more information, please follow other related articles on the PHP Chinese website!