I am creating a web page displaying information concerning items and trying to implement the following structures
- /ITEMS
| + /ITEMS/ITEM_1
| + /ITEMS/ITEM_2
...
The route /ITEM_LIST
contains an overview of all items and each /ITEMS/ITEM_X
contains specific information about the given item.
Since my item list is not static, I would like to create dynamically the ITEMS/ITEM_X
pages. For this purpose I have a function
def html_table_0(table: str, title: str = 'na'):
return render_template('table_template.html',
tables=[table],
titles=['na', title])
This works fine when I have one specific item:
obj_name = obj.name # (obj is an instance of custom class Obj representing my items)
@app.route('/objects/' + obj_name, methods=("POST", "GET"))
def html_table():
return render_template('table_template.html',
tables=[obj.to_html()],
titles=['na', obj.title])
But it fails when trying to do this iteratively.
I tried to make use of this SO post:
counter, routes = 0, [None]*obj_array.__len__()
for obj in obj_array:
routes[counter] = dict(route='/odds/'+obj.name,
func=lambda: html_table(table=obj.to_html()),
page=obj.name)
But this throws the exception
AssertionError: View function mapping is overwriting an existing endpoint function:
obj.name
Any guidance would appreciated.