title: How can I pass a value from a drop down list to another page in flask
body: <p>I want to have a page where an option is selected from a drop down list that is passed to the next page. The error I receive is "UnboundLocalError: local variable 'currentuser' referenced before assignment". I'm not sure how to update the variable globally when an option is selected from the drop down list or how to access the global variable locally in the next page function. I am new to python and flask, any help would be greatly appreciated!</p>
  
  <p><em>app.py</em></p>
  
  <pre><code>from flask import Flask, render_template
  import sqlite3
  app = Flask(__name__) 
  
  @app.route('/selectusername')
  def selectusername_page():
      # connect to database and populate userlist
      conn = sqlite3.connect('users.db')
      c = conn.cursor()
      c.execute("SELECT * FROM users")
      userlist = c.fetchall()
      conn.close()
      return render_template('selectusername.html', userlist=userlist)
  
  @app.route('/showusername')
  def showusername_page():
      currentuser=currentuser
      return render_template('showusername.html', currentuser=currentuser)
  
  if __name__ == '__main__':
      app.run(debug=True)
  
  </code></pre>
  
  <p><em>selectusername.html</em></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;body&gt;
      &lt;button onclick="window.location.href = 'showusername';"&gt;Continue&lt;/button&gt;
          &lt;h1&gt;Select User&lt;/h1&gt;
  &lt;select id="currentuser"&gt;
  {% for user in userlist %}
    &lt;option value="{{user[0]}}"&gt;{{user[0]}}&lt;/option&gt;
  {% endfor %}
  &lt;/select&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><em>showusername.html</em></p>
  
  <pre><code>&lt;h1&gt;Hello {{ currentuser }}&lt;/h1&gt;
  </code></pre>