title: Flask dynamic checkboxes
body: <p>This is pretty straightforward: I have a list of ids and I want to display them to the user as a series of checkboxes. The user should select the ones he wants then check which ones are selected and execute a function. Here's my code:</p>
  
  <p>app.py:</p>
  
  <pre><code>from flask import Flask, render_template, flash, request, redirect
  from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField,widgets, SelectMultipleField
  from flask_wtf import FlaskForm
  
  app = Flask(__name__)
  app.config.from_object(__name__)
  @app.route("/example", methods=["GET", "POST"])
      def example():
        form = FlaskForm()
        ids= ['a','b','c']
        if request.method == 'POST':
            selected_ids = request.form.getlist("ids")
            if form.validate():
                flash('nice')
            else:
                flash('something went wrong')
  
        return render_template('example.html', form=form, ids= ids)
  </code></pre>
  
  <p>and my template.html:</p>
  
  <pre><code>&lt;div class="container"&gt; 
      &lt;div class="content-section"&gt;
          &lt;form method="POST" action=""&gt;
              &lt;fieldset class="form-group"&gt;
                  &lt;legend class="border-bottom mb-4"&gt;IDs to select&lt;/legend&gt;
                  {%for i in ids%}
                  &lt;li&gt;
                          &lt;input type = "checkbox" id = "id_{{i}}" name = "ids" value = "1"&gt;
                          &lt;label for="id1"&gt;{{i}}&lt;/label&gt;
                   &lt;/li&gt;
                  {% endfor %}
  
              &lt;/fieldset&gt;
          &lt;button type="submit" class="btn btn-success"&gt;GO&lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>However, this creates a 500 error when I submit. Where am I going wrong? ANy suggestions highly appreciated!</p>