Home  >  Article  >  Backend Development  >  How to Extract Named Parameters from URLs in Flask?

How to Extract Named Parameters from URLs in Flask?

Barbara Streisand
Barbara StreisandOriginal
2024-10-26 19:47:02975browse

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>

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!

Statement:
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