title: How to pre-populate checkboxes with Flask/WTForms
body: <p>I'm trying to produce a dynamic checkbox list with certain boxes checked based on the state of the data.</p>
  
  <p>Here's my Form:</p>
  
  <pre><code>class FooForm(Form):
      bar = SelectMultipleField(
          'Bar',
          option_widget=CheckboxInput(),
          widget=ListWidget(prefix_label=True))
  </code></pre>
  
  <p>Here's the controller:</p>
  
  <pre><code>@app.route('/fooform', methods = ['GET','POST'])
  def foo():
      foos = foo_dao.find() 
      form = FooForm()
      form.bar.choices = [(foo.id, foo.label) for foo in foos]
      # SOMEHOW PRE-POPULATE CHECKBOXES HERE
      if form.is_submitted():
          # DO STUFF
      return render_template('foo.html', 
                             foos=foos,
                             form=form)
  </code></pre>
  
  <p>Here's the template:</p>
  
  <pre><code>  &lt;form action="" method="post" name="foos"&gt;
        {{form.bar}}
      &lt;p&gt;&lt;input type="submit" value="Add"&gt;&lt;/p&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>This produces a checkbox list, and it works, but I can't figure out how to specify which checkboxes in the list are to be pre-populated.</p>