1

I have an existing route in my flask application that looks like this:

@app.route('/<bucket_name>', methods=['GET'])
def list_objects(bucket_name):
    # many lines of awesome code here
    return 'a cool list of stuff'

Now I want to detect whether the query parameter location was pass to this same path. The parameter will not have a value : /foo?location.

Does flask allow me to setup a different route for this? I would prefer to not pollute my existing route with query parameter detection. I tried to add the route below, but it didn't work. My location requests get routed to the existing list_objects method

@app.route('/<bucket_name>?location', methods=['GET'])
def get_bucket_location(bucket_name):
    return 'bingo'

Note: I know how to read query parameters from my original route method. I am asking if there is a different way, especially in light of the fact that my query params will not have values. I need to detect the presence of a bunch of these types of params, and separate methods would be cleaner.

bigh_29
  • 2,529
  • 26
  • 22
  • 1
    *"Does flask allow me to setup a different route for this?"* - no, the query string isn't part of the routing. – jonrsharpe Oct 31 '17 at 12:38
  • 1
    @jonrsharpe It seems to me that the duplicate you've picked isn't really a duplicate (the other question doesn't address whether it's possible to make routing depend upon the query string) and that your comment ought to be an *answer* so it can be exposed to voting and commentary and so you or someone else can edit in some sort of supporting evidence like a quotation from the docs. As it is, you've basically answered in the comments and then closed as a duplicate of what's fundamentally a different question. – Mark Amery Jun 29 '18 at 16:22

0 Answers0