Getting value from select tag using flask

时间:2015-08-14 22:54:15

标签: python html flask

I'm new to Flask and I'm having trouble getting the value from my select tag. I have tried request.form['comp_select'] which returns a Bad Request. However, when I try using request.form.get('comp_select'), my return page returns a blank list "[]".

My html:

<form class="form-inline" action="{{ url_for('test') }}">
  <div class="form-group">
    <div class="input-group">
        <span class="input-group-addon">Please select</span>
            <select name="comp_select" class="selectpicker form-control">
              {% for o in data %}
              <option value="{{ o.name }}">{{ o.name }}</option>
              {% endfor %}                                              
            </select>
    </div>
    <button type="submit" class="btn btn-default">Go</button>
  </div>
</form>

My app.py:

@app.route("/test" , methods=['GET', 'POST'])
def test():
    select = request.form.get('comp_select')
    return(str(select)) # just to see what select is

Sorry in advance if my formatting is off for the post (also new to Stack Overflow).

0 个答案:

没有答案