Flask request
接收url中的参数
@app.route("/req") def req(): print(request.method) #获取访问方式 GET print(request.url) #获取url http://127.0.0.1:5000/req?id=1&name=wl print(request.cookies) #获取cookies {} print(request.path) # 获取访问路径 /req print(request.args) #获取url传过来的值 ImmutableMultiDict([('id', '1'), ('name', 'wl')]) print(request.args.get("id")) #get获取id 1 print(request.args["name"]) # 索引获取name wl print(request.args.to_dict()) # 获取到一个字典 {'id': '1', 'name': 'wl'} return "Hello"
@app.route("/login",methods=["POST","GET"]) def login(): print(request.form) # 格式 ImmutableMultiDict([('username', '123'), ('pwd', '123')]) print(request.form.to_dict()) # 格式 {'username': '123', 'pwd': '123'} return render_template("login.html")