title: How do I get a variable-length list of strings in an HTML form to Flask with WTForms?
body: <p>I am developing a question-and-answer web application with Flask and Flask-WTForms. Questions can have 1 to 5 tags, and I made a tag editor for users to input their tags:</p>
  
  <p><a href="https://i.stack.imgur.com/07pzj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/07pzj.png" alt="tag input with 2 tags below the input text area"></a></p>
  
  <p>I've written JavaScript code to serialize the tags into an array. So, in the image above that array looks like this: <code>["tag1","tag2"]</code>, and when tag3 gets added, it looks like this: <code>["tag1","tag2","tag3"]</code>.</p>
  
  <p>I need a way to get that list of tag names to my Flask view function, but I can't figure out how to do that. Any help would be greatly appreciated.</p>
  
  <p><strong>The form:</strong></p>
  
  <pre><code>class AskQuestionForm(Form):
      title = StringField('Title', validators=[Required(), Length(min=15, max=200)])
      content = TextAreaField('Content', validators=[Required(), Length(min=50, max=30000)])
  
      submit = SubmitField('Submit')
  </code></pre>
  
  <p><strong>The view function:</strong></p>
  
  <pre><code>@main.route('/ask/', methods=['GET', 'POST'])
  def ask_question():
      form = AskQuestionForm()
      if form.validate_on_submit():
          # Code to add a new question
      else:
          return render_template('ask.html', form=form)
  </code></pre>
  
  <p><strong>The template (simplified):</strong></p>
  
  <pre><code>&lt;form id="ask-question-form" method="post" action="{{ url_for('main.ask_question') }}"&gt;
      {{ form.csrf_token }}
  
      &lt;label for="title"&gt;Title&lt;/label&gt;
      &lt;input type="text" name="title" id="title"&gt;
  
      &lt;label for="content"&gt;Content&lt;/label&gt;
      &lt;textarea name="content" id="content"&gt;&lt;/textarea&gt;
  
      &lt;label for="tags"&gt;Tags&lt;/label&gt;
      &lt;input type="text" name="tags" id="add-tag-input"&gt;
      &lt;span&gt;
          &lt;button id="add-tag-button" type="button"&gt;Add&lt;/button&gt;
      &lt;/span&gt;
  
      &lt;button type="submit"&gt;Submit question&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>How can I get the list of tags to my Flask view function?</strong> Any help would be appreciated.</p>