jeudi 23 février 2017

getting select values with flask

I'm using html tag in my website but I'm not sure how to get it to submit back to flask. Do I need a submit button? Every time I try to submit I get an error "Bad Request: The browser (or proxy) sent a request that this server could not understand."

Here's my html:

<div class="two columns">
    <form name="cat" action="" method="post">
        <select name="cat">
            <option value="cats" >Categories</option>
            <option value="soon" >starting soon</option>
            <option value="football" >football</option>
            <option value="baseball" >baseball</option>
            <option value="basketball" >basketball</option>
            <option value="hockey">hockey</option>
        </select>
    </form>
</div>

and here's my function that I want to get the values from:

@app.route('/search_book', methods=['GET', 'POST'])
def search_book():

    if request.form['cat']:
        search = request.form['cat']

    print search

    return render_template('book.html')




Aucun commentaire:

Enregistrer un commentaire