Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

python - Passing variables through URL to a flask app

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...