title: WTForms in Flask: UndefinedError: 'form' is undefined
body: <p>I'm new to Flask and WTForms, and I cannot render my HTML page. I've been through the WTforms documentation again and again, but I can't find the source of the error: </p>
  
  <pre><code>jinja2.exceptions.UndefinedError, UndefinedError: 'form' is undefined
  </code></pre>
  
  <p>My code is below:</p>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>from flask.ext.wtf import Form
  from wtforms import TextField, BooleanField, TextAreaField, StringField, PasswordField, SelectField, validators
  
  class LoginForm(Form):
      username = TextField('Username', [
          validators.Required(), 
          validators.Length(min=4, max=25)
      ])
      password = PasswordField('New Password', [
          validators.Required()
      ])
  </code></pre>
  
  <p><strong>app.py</strong></p>
  
  <pre><code>from forms import *
  from wtforms import Form, fields, BooleanField, TextField, StringField,     PasswordField, validators
  from werkzeug.security import generate_password_hash, \
   check_password_hash
  
  @app.route('/login/', methods=['GET', 'POST'])
  def login():
      form = LoginForm(request.form)
      if request.method == 'POST' and form.validate():
          if load_user(form.username.data) is None:
              flash('Invalid username')
          else: 
              if check_password_hash(cred.password, form.password.data):
                  return redirect(url_for('browse'))  
              else: 
                  flash('Invalid password')
      return render_template('login.html', title='Login', form=form)
  </code></pre>
  
  <p><strong>login.html</strong></p>
  
  <pre><code>{% extends "base.html" %}
  {% block body %}
      &lt;form action="{{ url_for('login') }}" method="Post"&gt;
          &lt;fieldset&gt;
              &lt;div&gt;{{ form.username.label }}: {{ form.username() }}&lt;/div&gt;
              &lt;div&gt;{{ form.password.label }}: {{ form.password() }}&lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;button class="btn btn-default" type="submit"&gt;
                      &lt;span aria-hidden="true" class="glyphicon glyphicon-log-in"&gt;&lt;/span&gt;
                      Log In
                  &lt;/button&gt;
              &lt;/div&gt;
          &lt;/fieldset&gt;
      &lt;/form&gt;    
      &lt;div&gt;
      or &lt;a href="new"&gt;Register&lt;/a&gt; for an account
      &lt;/div&gt;
  {% endblock %}
  </code></pre>