Passing value from a drop down menu to a Flask template
You need to put your select
inside the form
.
<form name="Item_1" action="results.html" method='POST'> <select name="Item_1"> <option value="Red">Red</option> <option value="Green">Green</option> </select> <button type="submit">Compare!</button></form>
An even better way to declare the form
would be
<form name="Item_1" action="{{ url_for('results') }}" method="POST">
As mentioned by @dim put the select inside a the form and the chosen value can be got using request.form['Item_1']
. However the item being queried is a select, so I would prefer using get instead of POST. From wiki, http://en.wikipedia.org/wiki/POST_(HTTP), POST is used when
The POST request method is designed to request that a web server accept the data enclosed in the request message's body for storage.[1] It is often used when uploading a file or submitting a completed web form.
So I would rather prefer GET, which can be used to query the database. When using GET, Item_1 can be passed as request parameters and got using flask.request.args