Form validation in another route Flask
<p>I have a flask wtform. I am able to validate the form in a route where it is instantiated. But I want to validate it from another route. Without using session variable, Is there any other way by which I can access the form object from the other route?</p>

<p><strong>form_class.py</strong></p>

<pre><code>class Fruit ( Form):
    Fruit = SelectField ( choices = [ ( 0,"Select Fruit"), ( 1,'Apple'), (2,'Grape'), (3,'Orange') ], coerce = int, id="Fruit", validators = [Required()])  
</code></pre>

<p><strong>views.py</strong>: </p>

<pre><code>@app.route('/fruit',  methods = ['GET', 'POST'])
def fruit():
    form = Fruit()
    if form.validate_on_submit():
       return render_template("output.html")
    return render_template("name.html", form = form)
</code></pre>

<p><strong>name.html</strong></p>

<pre><code>&lt;form action="" method="POST"&gt;
      {{ form.hidden_tag() }}
      {{form.Fruit}}
      {{form.Fruit.errors}}
      &lt;input type = "submit"&gt;
&lt;/form&gt;
</code></pre>

<p>The above code works completely fine. But I want to do something like the below: </p>

<pre><code>@app.route('/fruit')
def fruit():
    form = Fruit()
    '''if form.validate_on_submit():
       return render_template("output.html")'''
    return render_template("name.html", form = form)

@app.route('/fruit_submit', methods = ['GET', 'POST'])
def fruit_submit():
    print request.form
    if form.validate_on_submit():
       return render_template("output.html")
</code></pre>

<p>I am getting the following error upon trying the above code.</p>

<pre><code>NameError: global name 'form' is not defined
</code></pre>

<p>You have to call the Fruit class with request.form</p>

<pre><code>@app.route('/fruit_submit', methods = ['GET', 'POST'])
def fruit_submit():
    print Fruit(request.form)
    if Fruit(request.form).validate_on_submit():
       return render_template("output.html")
</code></pre>

python flask flask-wtforms