Passing variables through URL to a flask app

后端 未结 2 1972
执笔经年
执笔经年 2020-12-19 12:58

Well i\'ve this in my flask app :

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

Now if i invoke it like :

相关标签:
2条回答
  • 2020-12-19 13:28

    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.

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

    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.

    0 讨论(0)
  • 2020-12-19 13:36

    You should use:

    app.route('/something/<ip>')
    def function(ip):
    

    And when you are using url_for, you should pass value of ip aswell:

    url_for('function', ip='your_ip_address')
    
    0 讨论(0)
提交回复
热议问题