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.