小编典典

如何使用 Flask 从 URL 获取命名参数?

all

当用户访问在我的烧瓶应用程序上运行的此 URL 时,我希望 Web 服务能够处理问号后指定的参数:

http://10.1.1.1:5000/login?username=alex&password=pw1

#I just want to be able to manipulate the parameters
@app.route('/login', methods=['GET', 'POST'])
def login():
    username = request.form['username']
    print(username)
    password = request.form['password']
    print(password)

阅读 97

收藏
2022-03-11

共1个答案

小编典典

用于request.args获取查询字符串的解析内容:

from flask import request

@app.route(...)
def login():
    username = request.args.get('username')
    password = request.args.get('password')
2022-03-11