How to Extract Named Parameters from URLs in Flask?

Barbara Streisand
Release: 2024-10-26 19:47:02
Original
974 people have browsed it

How to Extract Named Parameters from URLs in Flask?

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!