I’m building what should be a simple CRUD app with a Flask backend. Most of my endpoints have the exact same operations:
- Return a list of items
- Ingest a list from CSV
The only differentiators being the specific database table to draw from. I want to save time by defining these routes programatically. Something like this:
def define_routes(app):
ROUTES = {
'/list1': lambda : handle_list(model1),
'/list2': lambda : handle_list(model2),
# ...
}
for url in ROUTES:
app.add_url_rule(url, view_func=ROUTES[url])
def handle_list(dbModel):
if request.method == 'GET':
# return the list
if request.method == 'POST':
# ingest the list
but when I try to run this I get this error: AssertionError: View function mapping is overwriting an existing endpoint function: <lambda>
Why am I getting this error when I use anonymous lambda functions? Is there a way to do what I’m trying to do?