title: Flask WTF giving me jinja2.exceptions.UndefinedError: 'form' is undefined
body: <p>I know there are many cases out there that throws this error, and I search really hard on stackoverflow and other sites but I could not figure out why form is keep being undefined. Any help will really be appreciated</p>
  <p>I have <code>wtf_input.py</code> which have all the <code>wtf</code> defined like below</p>
  <pre><code>class InputForm(Form):
  
  # individual_first_name: DataRequired, is_name_non_digit, is_name_length, is_english
  first_name = StringField(&quot;First Name&quot;, [validators.DataRequired(&quot;Please enter first name&quot;),
                                                             I.is_name_non_digit, I.is_name_length, I.is_english])
  
  # individual_last_name: DataRequired, is_name_non_digit, is_name_length, is_english
  last_name = StringField(&quot;Last Name&quot;, [validators.DataRequired(&quot;Please enter last name&quot;),
                                                             I.is_name_non_digit, I.is_name_length, I.is_english])
  
  # date_of_birth:
  date_of_birth = DateField('date_of_birth', [validators.DataRequired('Birth date is required')], format='%Y-%m-%d',
                            description='Date format: YYYY-MM-DD', default='2001-02-02')
     .
     .
     . a lot more 
  </code></pre>
  <p>I is the class(calling static method) where my custom validator class is at.</p>
  <p>my view/test.py (where all my view is at)</p>
  <pre><code>from app.views.wtf_input import InputForm
  @test_blueprint.route('/')
  def index():
  
     return render_template('wtf_input.html')
  
  
  @test_blueprint.route('/post_user', methods=['GET', 'POST'])
  def post_user():
  
     form = InputForm()
  
     if form.validate():
         return render_template('wtf_input.html', form=form)
  </code></pre>
  <p>This is giving me the below error</p>
  <pre class="lang-py prettyprint-override"><code>Traceback (most recent call last)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py&quot;, line 2000, in __call__
  return self.wsgi_app(environ, start_response)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py&quot;, line 1991, in wsgi_app
  response = self.make_response(self.handle_exception(e))
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py&quot;, line 1567, in handle_exception
  reraise(exc_type, exc_value, tb)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/_compat.py&quot;, line 33, in reraise
  raise value
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py&quot;, line 1988, in wsgi_app
  response = self.full_dispatch_request()
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py&quot;, line 1641, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py&quot;, line 1544, in handle_user_exception
  reraise(exc_type, exc_value, tb)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/_compat.py&quot;, line 33, in reraise
  raise value
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py&quot;, line 1639, in full_dispatch_request
  rv = self.dispatch_request()
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py&quot;, line 1625, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File &quot;/Users/genomics/PycharmProjects/SA_test/app/views/post_inputs.py&quot;, line 62, in index
  return render_template('wtf_input.html')
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/templating.py&quot;, line 134, in render_template
  context, ctx.app)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/templating.py&quot;, line 116, in _render
  rv = template.render(context)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/jinja2/environment.py&quot;, line 989, in render
  return self.environment.handle_exception(exc_info, True)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/jinja2/environment.py&quot;, line 754, in handle_exception
  reraise(exc_type, exc_value, tb)
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/jinja2/_compat.py&quot;, line 37, in reraise
  raise value.with_traceback(tb)
  File &quot;/Users/genomics/PycharmProjects/SA_test/app/templates/wtf_input.html&quot;, line 9, in top-level template code
  {% for message in form.name.errors %}
  File &quot;/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/jinja2/environment.py&quot;, line 408, in getattr
  return getattr(obj, attribute)
  jinja2.exceptions.UndefinedError: 'form' is undefined
  
  </code></pre>
  <p>And I really cannot figure out what is going on.</p>
  <p>Can someone please help me out on this?</p>
  <p>Thanks</p>