title: Flask: Create routes dynamically
body: <p>I am creating a web page displaying information concerning items and trying to implement the following structures</p>
  
  <pre><code> - /ITEMS
   |           + /ITEMS/ITEM_1
   |           + /ITEMS/ITEM_2
   ...
  </code></pre>
  
  <p>The route <code>/ITEM_LIST</code> contains an overview of all items and each <code>/ITEMS/ITEM_X</code> contains specific information about the given item.</p>
  
  <p>Since my item list is <em>not</em> static, I would like to create dynamically the <code>ITEMS/ITEM_X</code> pages. For this purpose I have a function</p>
  
  <pre><code>def html_table_0(table: str, title: str = 'na'):
      return render_template('table_template.html',
                             tables=[table],
                             titles=['na', title])
  </code></pre>
  
  <p>This works fine when I have one specific item:</p>
  
  <pre><code>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])
  </code></pre>
  
  <p>But it fails when trying to do this iteratively.</p>
  
  <p>I tried to make use of this <a href="https://stackoverflow.com/questions/38417563/dynamically-generate-flask-routes/38418023">SO post</a>:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>But this throws the exception</p>
  
  <blockquote>
    <p>AssertionError: View function mapping is overwriting an existing endpoint function: <code>obj.name</code></p>
  </blockquote>
  
  <p>Any guidance would appreciated.</p>