I'm learning Flask and have a question about dynamic routing: is it possible to pass in a list of accepted routes? I noticed the any
converter which has potential but had a hard time finding examples of it in use. Basically I have different groups of endpoints that should trigger the same action amongst them. Here's what I mean:
cities = [New York, London, Tokyo]
food = [eggs, bacon, cheese]
actions = [run, walk, jump]
I could do something like
@app.route('/<string:var>', methods = ['GET'])
def doSomething(var):if var in cities:travel(var)else if var in food:eat(var)else if var in action:perform(var)
But is there any way I can do something like this?
@app.route('/<any(cities):var>', methods = ['GET'])def travel(var):@app.route('/<any(food):var>', methods = ['GET'])def eat(var)@app.route('/<any(actions):var>', methods = ['GET'])def perform(var)
Additionally, I want these lists to be dynamic. So what I really want is something like:
cities = myDb.("SELECT cities FROM country")
@app.route('/<any(cities):var>', methods = ['GET'])def travel(var):
Is there any way to achieve this, or am I stuck blocking everything up in one dynamic route?