from flask import request, render_template

from ca import app, db
from ca.forms import RequestForm
from ca.models import Request


@app.route('/', methods=['GET'])
def index():
    return render_template('index.html')


@app.route('/', methods=['POST'])
def post_request():
    form = RequestForm(request.form)
    if form.validate():
        req = Request(form.id.data, form.email.data)
        db.session.add(req)
        db.session.commit()
        return render_template('thanks.html')
    else:
        return render_template('index.html', form=form)

from flask import request, render_template

from ca import app, db
from ca.forms import RequestForm
from ca.models import Request


@app.route('/', methods=['GET'])
def index():
    form = RequestForm()
    return render_template('index.html', form=form)


@app.route('/', methods=['POST'])
def post_request():
    form = RequestForm(request.form)
    if form.validate():
        req = Request(form.id.data, form.email.data)
        db.session.add(req)
        db.session.commit()
        return render_template('thanks.html')
    else:
        return render_template('index.html', form=form)

Create form on index view
Create form on index view

- Need to always pass a form to the view
  - make sure to create on for the `GET` view
- Fixes #33

  from flask import request, render_template
  
  from ca import app, db
  from ca.forms import RequestForm
  from ca.models import Request
  
  
  @app.route('/', methods=['GET'])
  def index():
+     form = RequestForm()
-     return render_template('index.html')
+     return render_template('index.html', form=form)
  
  
  @app.route('/', methods=['POST'])
  def post_request():
      form = RequestForm(request.form)
      if form.validate():
          req = Request(form.id.data, form.email.data)
          db.session.add(req)
          db.session.commit()
          return render_template('thanks.html')
      else:
          return render_template('index.html', form=form)
  
Create form on index view
## Code Before:
from flask import request, render_template

from ca import app, db
from ca.forms import RequestForm
from ca.models import Request


@app.route('/', methods=['GET'])
def index():
    return render_template('index.html')


@app.route('/', methods=['POST'])
def post_request():
    form = RequestForm(request.form)
    if form.validate():
        req = Request(form.id.data, form.email.data)
        db.session.add(req)
        db.session.commit()
        return render_template('thanks.html')
    else:
        return render_template('index.html', form=form)

## Instruction:
Create form on index view
## Code After:
from flask import request, render_template

from ca import app, db
from ca.forms import RequestForm
from ca.models import Request


@app.route('/', methods=['GET'])
def index():
    form = RequestForm()
    return render_template('index.html', form=form)


@app.route('/', methods=['POST'])
def post_request():
    form = RequestForm(request.form)
    if form.validate():
        req = Request(form.id.data, form.email.data)
        db.session.add(req)
        db.session.commit()
        return render_template('thanks.html')
    else:
        return render_template('index.html', form=form)
