title: Flask: NameError: global name 'redirect' is not defined
body: <p>I'm trying to make a form that saves the form input as URL queries. However, I don't know why this is happening when I press the form's submit button. I'm sure it has something to do with redirect() or my form.</p>
  
  <p><strong>site.py</strong></p>
  
  <pre><code>from flask import Flask, render_template, request
  
  app = Flask(__name__)
  
  @app.route('/')
  def index():
      return render_template("about.html")
  
  @app.route('/hobbies/')
  def blog():
      return render_template("hobbies.html")
  
  @app.route('/about/')
  def about():
      return render_template("about.html")
  
  @app.route('/projects/', methods=['GET', 'POST'])
  def projects():
      return render_template("projects.html")
  
  @app.route('/dress')
  def dress():
      return render_template("dress.html")
  
  @app.route('/dress', methods=['GET', 'POST'])
  def my_form_post():
      min_bust = request.form['min_bust']
      max_bust = request.form['max_bust']
      min_waist = request.form['min_waist']
      max_waist = request.form['max_waist']
      min_length = request.form['min_length']
      max_length = request.form['max_length']
      return redirect(url_for('/dress/', 
                               min_bust=min_bust,
                               max_bust=max_bust, 
                               min_waist=min_waist, 
                               max_waist=max_waist, 
                               min_length=min_length, 
                               max_length=max_length), code=302)
  
  @app.route('/base/')
  def base():
      return render_template("base.html")
  
  @app.errorhandler(404)
  def page_not_found(e):
      return render_template("404.html"), 404
  
  @app.errorhandler(500)
  def internal_server_error(e):
      return render_template('500.html'), 500
  
  if __name__ == '__main__':
      app.run(debug=True)
  </code></pre>
  
  <p><strong>dress.html:</strong></p>
  
  <pre><code>{% extends "base.html" %}
  
  {% block title %}Dress Finder{% endblock %}
  
  {% block menu %}
  &lt;div class="menu"&gt;
      &lt;a href="http://localhost:5000/hobbies/"&gt;&lt;div class="button"&gt;Hobbies&lt;/div&gt;&lt;/a&gt;
      &lt;a href="http://localhost:5000/about/"&gt;&lt;div class ="button"&gt; Katie&lt;/div&gt;&lt;/a&gt;
      &lt;a href="http://localhost:5000/projects/"&gt;&lt;div class="button" id="current_page"&gt;Projects&lt;/div&gt;&lt;/a&gt;
  &lt;/div&gt;
  {% endblock %}
  
  {% block content %}
  Dress Finder
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  Input desired Bust/Waist/Length measurements in inches and Dress Finder does the rest.
  &lt;br&gt;&lt;br&gt;
  &lt;form action="/dress" method="POST"&gt;
    &lt;input type="text" name="min_bust" placeholder="Min Bust Size" class="input"&gt; 
    to &lt;input type="text" name="max_bust" placeholder="Max Bust Size" class="input"&gt; 
    &lt;br&gt;&lt;br&gt;
    &lt;input type="text" name="min_waist" placeholder="Min Waist" class="input"&gt; 
    to &lt;input type="text" name="max_waist" placeholder="Max Waist" class="input"&gt; 
    &lt;br&gt;&lt;br&gt;
    &lt;input type="text" name="min_length" placeholder="Min Length" class="input"&gt; 
    to &lt;input type="text" name="max_length" placeholder="Max Length" class="input"&gt; 
    &lt;br&gt;&lt;br&gt;
    &lt;input type="submit" name="my-form" value="                 submit                 " class="prettyButton"&gt;
  &lt;/form&gt;
  {% endblock %}
  </code></pre>