title: Flask-WTForms: dynamically create name and id attributes
body: <p>My form allows the user to enter a specific number of names for a specific number of basketball teams. These numbers are constantly updated so I need to create a dynamic form.</p>
  
  <p>Let's say I have the following Flask view:</p>
  
  <pre><code>@app.route('/dynamic', methods=['GET', 'POST'])
  def dynamic():
      teams = ['Warriors', 'Cavs']
      name_count = 2
      return render_template('dynamic.html', teams=teams, name_count=name_count)
  </code></pre>
  
  <p>And the following form in the HTML template <code>dynamic.html</code>:</p>
  
  <pre><code>&lt;form method='POST' action='/dynamic'&gt;
    {% for team_index in range(teams | count) %}
      {% for name_index in range(name_count) %}
        &lt;input type="text"
               class="form-control"
               id="team{{ team_index }}_name{{ name_index }}"
               name="team{{ team_index }}_name{{ name_index }}"&gt;
      {% endfor %}
    {% endfor %}
  &lt;form&gt;
  </code></pre>
  
  <p>Which yields the following form:</p>
  
  <pre><code>&lt;form method='POST' action='/dynamic'&gt;
    &lt;input type="text" class="form-control" id="team0_name0" name="team0_name0"&gt;
    &lt;input type="text" class="form-control" id="team0_name1" name="team0_name1"&gt;
    &lt;input type="text" class="form-control" id="team1_name0" name="team1_name0"&gt;
    &lt;input type="text" class="form-control" id="team1_name1" name="team1_name1"&gt;
  &lt;form&gt;
  </code></pre>
  
  <p>I love the <a href="https://flask-wtf.readthedocs.io/" rel="nofollow noreferrer">Flask-WTF</a> library so I'm wondering how I can use that (or simply <a href="https://wtforms.readthedocs.io/en/latest/" rel="nofollow noreferrer">wtforms</a>) to render this form. I'm not sure this is even possible because wtforms requires a hardcoded field name for every input.</p>