title: Passing value from a drop down menu to a Flask template
body: <p>I am having an issue passing an item selected from an HTML drop down menu to a SQL query.</p>
  
  <p>I'm not exactly sure what concept is missing from my code to make this work. Most examples I have found are in PHP and I'm not sure how to translate it to Python.</p>
  
  <p>Here is the scenario. I'm using Flask and Sqlite and am try to let the user select an item from an HTML drop down menu. The item selected from the drop down menu will be used in a SQL query to retrieve information from a database and then display those results on a new page.</p>
  
  <p>An example, the user selects "Red" from a drop down that has 3 options (Red, Blue, Green) and clicks a submit button. "Red" will be passed to a SQL query in my app.py file that will retrieve all data from rows where color = "Red". That retrieved data will then be displayed on /results.html.</p>
  
  <p>I believe my problem is that I'm not correctly attributing a value to the items in my drop down menu and then passing that value to my Python code that is running the SQL query. This is my assumption on how this should work, but I might be missing something bigger here.</p>
  
  <p>I have tried lots of bits of HTML to make this work, but I'm not even sure that is where my problem is occurring. When I hit "Submit" I'm taking the new page, but nothing from the database is displayed</p>
  
  <p>Here is my code, for my 2 views ('/' &amp; 'results.html') and my Python code: </p>
  
  <pre><code>@app.route('/results.html', methods=['GET','POST'])
  def results():
      g.db = connect_db()
  
      cur = g.db.execute("SELECT * FROM all_items WHERE name = '{}'".format('Red'))
      posts = [dict(item=row[0], name=row[1]) for row in cur.fetchall()]
      g.db.close()
      return render_template('results.html', posts=posts)
  </code></pre>
  
  <p>Here is View where the the drop down menus exist</p>
  
  <pre><code>&lt;select name="Item_1"&gt;
      &lt;option value="Red"&gt;Red&lt;/option&gt;
      &lt;option value="Green"&gt;Green&lt;/option&gt;        
  &lt;/select&gt;
  
  &lt;form name="Item_1" action="results.html" method='POST'&gt;
      &lt;button type="submit"&gt;Compare!&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is the View where the results from selecting "Red" should be displayed</p>
  
  <pre><code>% extends "template.html" %}
  {% block content %}
  &lt;h2&gt;Results&lt;/h2&gt;
  
  {% for p in posts %}
      &lt;strong&gt;Item:&lt;/strong&gt; {{ p.item }}
      &lt;strong&gt;Name:&lt;/strong&gt; {{ p.name}}  
  {% endfor %}
  {% endblock %}
  </code></pre>