title: How do i resolve this Flask-WTF issue: Jinja2.exceptions.UndefinedError: 'wtforms.fields.core.UnboundField object' has no attribute 'label'
body: <p>I am relatively new to coding so I apologize for any vagueness or error. Please do correct me. I have been following Corey Schafers Flask Tutorial and on part 3 I've been stuck with the following error: Jinja2.exceptions.UndefinedError: 'wtforms.fields.core.UnboundField object' has no attribute 'label', while trying to run the following registration page:</p>
  
  <p><strong>register.html</strong></p>
  
  <pre><code>{% extends "layout.html" %}
  {% block content %}
      &lt;div class="content-section"&gt;
          &lt;form method="POST" action=""&gt;
              {{ form().hidden_tag() }}
              &lt;fieldset class="form-group"&gt;
                  &lt;legend class="border-bottom mb-4"&gt;Join Today&lt;/legend&gt;
                  &lt;div class="form-group"&gt;
                      {{ form.username.label(class="form-control-label") }}
  
                      {% if form.username.errors %}
                          {{ form.username(class="form-control form-control-lg is-invalid") }}
                          &lt;div class="invalid-feedback"&gt;
                              {% for error in form.username.errors %}
                                  &lt;span&gt;{{ error }}&lt;/span&gt;
                              {% endfor %}
                          &lt;/div&gt;
                      {% else %}
                          {{ form.username(class="form-control form-control-lg") }}
                      {% endif %}
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      {{ form.email.label(class="form-control-label") }}
                      {% if form.email.errors %}
                          {{ form.email(class="form-control form-control-lg is-invalid") }}
                          &lt;div class="invalid-feedback"&gt;
                              {% for error in form.email.errors %}
                                  &lt;span&gt;{{ error }}&lt;/span&gt;
                              {% endfor %}
                          &lt;/div&gt;
                      {% else %}
                          {{ form.email(class="form-control form-control-lg") }}
                      {% endif %}
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      {{ form.password.label(class="form-control-label") }}
                      {% if form.password.errors %}
                          {{ form.password(class="form-control form-control-lg is-invalid") }}
                          &lt;div class="invalid-feedback"&gt;
                              {% for error in form.password.errors %}
                                  &lt;span&gt;{{ error }}&lt;/span&gt;
                              {% endfor %}
                          &lt;/div&gt;
                      {% else %}
                          {{ form.password(class="form-control form-control-lg") }}
                      {% endif %}
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      {{ form.confirm_password.label(class="form-control-label") }}
                      {% if form.confirm_password.errors %}
                          {{ form.confirm_password(class="form-control form-control-lg is-invalid") }}
                          &lt;div class="invalid-feedback"&gt;
                              {% for error in form.confirm_password.errors %}
                                  &lt;span&gt;{{ error }}&lt;/span&gt;
                              {% endfor %}
                          &lt;/div&gt;
                      {% else %}
                          {{ form.confirm_password(class="form-control form-control-lg") }}
                      {% endif %}
                  &lt;/div&gt;
              &lt;/fieldset&gt;
              &lt;div class="form-group"&gt;
                  {{ form.submit(class="btn btn-outline-info") }}
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
      &lt;div class="border-top pt-3"&gt;
          &lt;small class="text-muted"&gt;
              Already Have An Account? &lt;a class="ml-2" href="{{ url_for('login') }}"&gt;Sign In&lt;/a&gt;
          &lt;/small&gt;
      &lt;/div&gt;
  {% endblock content %}
  
  </code></pre>
  
  <p><strong> Additional Involved files: </strong></p>
  
  <p><strong> forms.py </strong></p>
  
  <pre><code>from flask_wtf import FlaskForm
  from wtforms import StringField, PasswordField, SubmitField, BooleanField
  from wtforms.validators import DataRequired, Length, Email, EqualTo
  
  class RegistrationForm(FlaskForm):
      username = StringField('Username',
                             validators=[DataRequired(), Length(min=2, max=20)])
      email = StringField('Email',
                          validators=[DataRequired(), Email()])
      password = PasswordField('Password', validators=[DataRequired()])
      confirm_password = PasswordField('Confirm Password',
                                       validators=[DataRequired(), EqualTo('password')])
      submit = SubmitField('Sign Up')
  
  
  class LoginForm(FlaskForm):
      email = StringField('Email',
                          validators=[DataRequired(), Email()])
      password = PasswordField('Password', validators=[DataRequired()])
      remember = BooleanField('Remember Me')
      submit = SubmitField('Login')
  
  </code></pre>
  
  <p><strong>flaskblog.py</strong></p>
  
  <pre><code>from flask import Flask, render_template, url_for
  from forms import RegistrationForm, LoginForm
  ...
  @app.route('/register')
  def register():
      form = RegistrationForm
      return render_template('register.html', title='register', form=form)
  </code></pre>
  
  <p><strong>This is the traceback from the server:</strong></p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\app.py", line 2464, in __call__
      return self.wsgi_app(environ, start_response)
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\app.py", line 2450, in wsgi_app
      response = self.handle_exception(e)
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\app.py", line 1867, in handle_exception
      reraise(exc_type, exc_value, tb)
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\_compat.py", line 39, in reraise
      raise value
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\app.py", line 2447, in wsgi_app
      response = self.full_dispatch_request()
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\app.py", line 1952, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\_compat.py", line 39, in reraise
      raise value
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
      rv = self.dispatch_request()
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\app.py", line 1936, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "C:\Users\Musa\Desktop\Flask_Blog\flask_blog.py", line 39, in register
      return render_template('register.html', title='register', form=form)
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\templating.py", line 140, in render_template
      ctx.app,
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\flask\templating.py", line 120, in _render
      rv = template.render(context)
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\jinja2\environment.py", line 1090, in render
      self.environment.handle_exception()
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\jinja2\environment.py", line 832, in handle_exception
      reraise(*rewrite_traceback_stack(source=source))
    File "C:\Users\Musa\Desktop\Flask_Blog\lib\site-packages\jinja2\_compat.py", line 28, in reraise
      raise value.with_traceback(tb)
    File "C:\Users\Musa\Desktop\Flask_Blog\templates\register.html", line 1, in top-level template code
      {% extends "layout.html" %}
    File "C:\Users\Musa\Desktop\Flask_Blog\templates\layout.html", line 47, in top-level template code
      {% block content %}{% endblock %}
    File "C:\Users\Musa\Desktop\Flask_Blog\templates\register.html", line 9, in block "content"
      {{ form.username.label(class="form-control-label") }}
  jinja2.exceptions.UndefinedError: 'wtforms.fields.core.UnboundField object' has no attribute 'label'
  
  </code></pre>
  
  <p>How do I approach resolving this issue? I tried looking at the WTForms Documentation and it said that: </p>
  
  <p>"_If _form and _name isn’t provided, an UnboundField will be returned instead. Call its bind() method with a form instance and a name to construct the field."</p>
  
  <p><a href="https://wtforms.readthedocs.io/en/stable/fields/#wtforms.fields.Label" rel="nofollow noreferrer">https://wtforms.readthedocs.io/en/stable/fields/#wtforms.fields.Label</a></p>
  
  <p>So I Know that label attribute is not receiving a form or a name but then what is form-control doing?
  I don't know how to make sense of this. 
  I tried proofreading the code on Corey Schafer's git folder but still to no avail:
  <a href="https://github.com/CoreyMSchafer/code_snippets/tree/master/Python/Flask_Blog/03-Forms-and-Validation" rel="nofollow noreferrer">https://github.com/CoreyMSchafer/code_snippets/tree/master/Python/Flask_Blog/03-Forms-and-Validation</a>
  please do help!</p>