title: Implementing a Modal Form with Flask
body: <p>I'm a junior developer and I have been having a hard time trying to implement a modal form in Flask. Both the Sign Up Modal and the Login Modal are on the same HTML page. It keeps saying form undefined. below is the code </p>
  
  <p>The code in my form.py</p>
  
  <pre><code>class SignupForm(Form):
      username = StringField('', [validators.Length(min=4, max=30)])
      email = StringField('', [validators.length(min=6, max=50)])
      password = PasswordField('', [
          validators.DataRequired(),
          validators.EqualTo('confirm', message="Password do not match")])
      confirm = PasswordField('', [validators.length(min=6, max=50), validators.DataRequired()])
      create = SubmitField('Sign up')
  
  class LoginForm(Form):
      email = StringField(" ", [validators.Length(min=6, max=50), validators.DataRequired()])
      password = PasswordField('', [validators.DataRequired(),validators.Length(min=2, max=50)])
      submit = SubmitField('login')
      remember = BooleanField('remember me')`
  
  def signup():
      # mysql = MySQL(c_app)
      form  = SignupForm(request.form)
  
       return render_template('signup.html',form=form)
  
  @loginv.route("/login", methods=['GET', 'POST'])
  def login():
      form = LoginForm(request.form)
  
      return render_template("signin.html", form=form)
  </code></pre>
  
  <pre><code>Traceback (most recent call last):
      return original_handler(e)
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\flask\app.py", line 1737, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\flask\_compat.py", line 36, in reraise
      raise value
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\flask\app.py", line 1832, in full_dispatch_request
      rv = self.dispatch_request()
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\flask\app.py", line 1818, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "C:\Users\Mr Ayo\Desktop\my_social_trends\views\search.py", line 65, in search
      return render_template("index-home.html")
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\flask\templating.py", line 135, in render_template
      context, ctx.app)
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\flask\templating.py", line 117, in _render
      rv = template.render(context)
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\jinja2\asyncsupport.py", line 76, in render
      return original_render(self, *args, **kwargs)
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\jinja2\environment.py", line 1008, in render
      return self.environment.handle_exception(exc_info, True)
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\jinja2\environment.py", line 780, in handle_exception
      reraise(exc_type, exc_value, tb)
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\jinja2\_compat.py", line 37, in reraise
      raise value.with_traceback(tb)
    File "C:\Users\Mr Ayo\Desktop\my_social_trends\templates\index-home.html", line 1, in top-level template code
      {% extends 'main-layout.html' %}
    File "C:\Users\Mr Ayo\Desktop\my_social_trends\templates\main-layout.html", line 142, in top-level template code
      {{ form.name }}
    File "C:\Users\Mr Ayo\.virtualenvs\cta\lib\site-packages\jinja2\environment.py", line 430, in getattr
      return getattr(obj, attribute)
  jinja2.exceptions.UndefinedError: 'form' is undefined
  </code></pre>