Not too familiar with Flask, so it's possible there is a cleaner way to do this. (If someone who is knowledgeable about Flask thinks that my method is fundamentally wrong, I will be happy to delete my answer if they explain why in the comment.) Now that I have received this disclaimer, here are my thoughts:
app.route("/") is a decorator function. The @ notation is just syntactic sugar for something like index = app.route("/")(index) . Therefore, you should be able to do something like this ...
routes = [ ("/", index), ("/about", about) ] for route, view_func in routes: view_func = app.route(route)(view_func)
which allows you to create Flask routes from dynamically created routes and functions.
source share