title: Why is my flask form validation returning Not a valid choice?
body: <p>I have been trying to figure out why my Flask form will not properly validate my select field choices even though the choices are coming from the select field options.</p>
  
  <p>My assumption is that the select option when passed back from the server is unicode and is being compared to the choice which is a string, however, I thought coerce=str would fix that. I printed out the form data and request data which is the output below. Why isn't it working?</p>
  
  <p>My code is attached below, removed csrf token key from the output dict. It seems like a very simple thing, but I can't figure it out. </p>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class PlatformForm(FlaskForm):
      platform_options = [('test', 'Test'), ('test2','Test2')]
      platforms = wtforms.SelectField('Platforms', choices=platform_options, coerce=str, validators=[DataRequired()])
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>@app.route('/', methods=['POST', 'GET'])
  def index():
      form = forms.PlatformForm()
      if form.is_submitted():
          print form.data
          print request.form
      if form.errors:
          print form.errors
  return render_template('home.html', form=form)
  </code></pre>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>   {% extends "base.html" %}
     {% block content %}
     &lt;h4&gt;Select a Platform&lt;/h4&gt;
     &lt;form method="POST"&gt;
         {{ form.csrf_token }}
         &lt;select class="custom-select" name="platform"&gt;
         {% for value, text in form.platforms.choices %}&lt;br&gt;
             &lt;option value="{{ value }}"&gt;{{ text }}&lt;/option&gt;
         {% endfor %}
         &lt;/select&gt;
  &lt;button id="submit_inputs" type="submit" class="btn btn-default"&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
      {% endblock %}
  </code></pre>
  
  <p><strong><em>output</em></strong></p>
  
  <pre><code>   {'platforms': 'None'}
     ImmutableMultiDict([('platform', u'test')])
     {'platforms': [u'Not a valid choice']}
  </code></pre>
  
  <p>EDIT:
  I figured out the problem. It's the way I'm creating the Select drop down through HTML and Jinja. Iterating through the choices and creating option tags doesn't seem to instantiate anything in the form data itself when passed back into Python. Changing that whole for loop to just </p>
  
  <pre><code>{{form.platforms}}
  </code></pre>
  
  <p>created a select drop down field that actually works. </p>