在Flask中,如何从URL中提取参数?如何使用flask和python从URL中提取命名参数?
当用户访问我在烧瓶应用程序上运行的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)
Run Code Online (Sandbox Code Playgroud) 我有许多以逗号开头landingpage
并以唯一ID结尾的网址.我需要能够从URL获取id,以便我可以将一些数据从另一个系统传递到我的Flask应用程序.我怎样才能获得这个价值?
http://localhost/landingpageA
http://localhost/landingpageB
http://localhost/landingpageC
Run Code Online (Sandbox Code Playgroud) 好吧,我的烧瓶应用程序中有这个:
@app.route("/changeip/<ip>")
def change_ip(ip) :
return ip
Run Code Online (Sandbox Code Playgroud)
现在如果我调用它:
http://127.0.0.1:5000/changeip?ip=1.2.2.2
Run Code Online (Sandbox Code Playgroud)
它吐出"未找到网址"......我在这里做错了什么?