title: Flask WTForms dynamic select field from list instead of db
body: <p>I am attempting to create a dynamic drop down (SelectField) with WTForms. I have read the documentation and have looked at quite a few answers on stack, and all of the examples involve iterating over a db query. </p>
  
  <p>I simply want to iterate over a list (that's generated from an external API call) to inject the SelectField choices. For example:</p>
  
  <pre><code>class ToolForm(FlaskForm):
  
  
      myField3 = SelectField(u'Select Account', choices=[], coerce=int)
  
  
  @app.route("/test", methods=['GET', 'POST'])
  def test():
      form = ToolForm()
      accounts5 = []
  
      if request.method == 'POST':
          if request.form['submit_button'] == 'Select Account':
  
              #code that generates list called "accounts5"
  
              acctchoices = [(c.id,c.name) for c in accounts5]
              form.myField3.choices = acctchoices
  
      return render_template('test.html', title='test', form=form, accounts5=accounts5)
  </code></pre>
  
  <p>And my relevant HTML looks like:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      {{ form.myField3.label(class="form-control-label") }} {% if form.myField3.errors %} {{ 
      form.myField3(class="form-control form-control-lg is-invalid") }}
      &lt;div class="invalid-feedback"&gt;
          {% for errors in form.myField3.errors %}
          &lt;span&gt;{{ error }}&lt;/span&gt;
          {% endfor %}
      &lt;/div&gt;
      {% else %} {{ form.myField3(class="form-control form-control-lg") }} {% endif %}
  &lt;/div&gt;
  &lt;form action="http://127.0.0.1:5000/test" method="post"&gt;
  
  
      &lt;input type="submit" class="btn btn-outline-info" name="submit_button" value="Select Account"&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>When I click "Select Account" I get an <code>'int' object has no attribute 'id'</code> error. I thought this might be a data type issue so I tried with a list of strings but to no avail.</p>
  
  <p>My question is, how can I populate my SelectField from a list?</p>