How to get multiple selected items from Form in Flask

后端 未结 1 466
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 03:49

With the

having two list items selected \"Category 01\" and \"Category 03\":

 
    
相关标签:
1条回答
  • 2021-01-13 04:13

    You will want to use the getlist() function to get a list of values.

    First, change your form as below:

    <form> 
        <div class="form-group">
          <div>
            <select id="myform" name='category' multiple class="form-control"> // addition here
                <option> Category 01 </option>
                <option> Category 01 </option>
                <option> Category 01 </option>
            </select>
          </div>
        </div>
    </form> 
    

    And in your flask function:

    if request.method == 'POST':
        as_dict = request.form.getlist('myform')
        print request
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题