12

So, I have the following route in Flask:

@app.route("/menu-card/<google_place_id>", methods=['GET']) 

On navigating to http://127.0.0.1:5000/menu-card/ChIJAxXhIUMUrjsR5QOqVsQjCCI, I get the proper response.

However, then I tried changing the URL pattern as follows:

@app.route("/menu-card?id=<google_place_id>", methods=['GET']) 

On navigating to http://127.0.0.1:5000/menu-card?id=ChIJAxXhIUMUrjsR5QOqVsQjCCI I now get a 404 error. What am I doing wrong ?

0

1 Answer 1

14

The part after the ? is the query string, which you can get using request.args. So, your route should be:

@app.route("/menu-card", methods=['GET']) 

and then you can get the id by using:

google_place_id = request.args.get('id', None) 

where None is the default value, if id is not included in the url. You'll have to check if that it's not equal to None to make sure it has been passed.

Search the quickstart page for request.args to see another example.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks..exactly what I wanted..
Link is dead, here is the official documentation
Thanks @RunOrVeith, fixed the link

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.