Python Flask 后台如何获取 URL 提交的 参数?

************************************************************
Python Flask 后台如何获取 URL 提交的 参数?

方法一用 request.form['username'] 与  request.form['password']

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


方法二:request.args.get    

from flask import request

@app.route(...)
def login():
    username = request.args.get('username')
    password = request.args.get('password')
    
#request.args.get 中,各个参数说明
from flask import request
@app.route('/my-route')
def my_route():
  page = request.args.get('page', default = 1, type = int)
  filter = request.args.get('filter', default = '*', type = str)

 

你可能感兴趣的:(Python)