通过URL将变量传递给Flask应用 [英] Passing variables through URL to a flask app

查看:59
本文介绍了通过URL将变量传递给Flask应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我已经在我的烧瓶应用程序中找到了它:

Well i've this in my flask app :

@app.route("/changeip/<ip>")
def change_ip(ip) :
    return ip

现在,如果我像这样调用它:

Now if i invoke it like :

http://127.0.0.1:5000/changeip?ip=1.2.2.2

它吐出找不到URL" ...我在这里做错什么了吗?

It spits out "URL not found"...what is that i'm doing wrong here?

推荐答案

第一个路由描述了一个URL,该URL中包含一个值.第二个网址描述的路由没有变量,但网址中带有查询参数.

The first route describes a url with a value as part of the url. The second url describes a route with no variables, but with a query parameter in the url.

如果您使用的是第一个路由,则网址应类似于 http://127.0.0.1/changeip/1.2.2.2 .

If you are using the first route, the url should look like http://127.0.0.1/changeip/1.2.2.2.

如果您使用的是第二个url,则路由应类似于/changeip ,函数应为 def change_ip():,并且应从中读取值 request.args ['ip'] .

If you are using the second url, the route should look like /changeip, the function should be def change_ip():, and the value should be read from request.args['ip'].

通常,路由应描述应始终存在的所有参数,并且表单或查询参数应用于用户提交的数据.

Usually the route should describe any arguments that should always be present, and form or query params should be used for user-submitted data.

这篇关于通过URL将变量传递给Flask应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆