"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Extract Named Parameters from URLs in Flask?

How to Extract Named Parameters from URLs in Flask?

Published on 2024-11-07
Browse:137

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.

from flask import request

@app.route('/login', methods=['GET', 'POST'])
def login():
    username = request.args.get('username')
    password = request.args.get('password')

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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3