title: Display Result in Same Page Using python flask
body: <p>I am using python flask for sending form data into another HTML template. I need to show the result in same page where HTML input form exists. Currently response is being forwarded to next page.</p>
  
  <p>I tried to run via JQuery but still unable to get the result.</p>
  
  <p>app.py</p>
  
  <pre><code>from flask import Flask, render_template, request
  app = Flask(__name__)
  
  @app.route('/')
  def student():
     return render_template('index.html')
  
  @app.route('/result',methods = ['POST', 'GET'])
  def result():
     if request.method == 'POST':
        result = request.form
        return render_template("result.html",result = result)
  
  if __name__ == '__main__':
     app.run(debug = True)
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;html&gt;
     &lt;body&gt;
        &lt;form action = "http://localhost:5000/result" method = "POST"&gt;
           &lt;p&gt;Name &lt;input type = "text" name = "Name" /&gt;&lt;/p&gt;
           &lt;p&gt;Physics &lt;input type = "text" name = "Physics" /&gt;&lt;/p&gt;
           &lt;p&gt;Chemistry &lt;input type = "text" name = "chemistry" /&gt;&lt;/p&gt;
           &lt;p&gt;Maths &lt;input type ="text" name = "Mathematics" /&gt;&lt;/p&gt;
           &lt;p&gt;&lt;input type = "submit" value = "submit" /&gt;&lt;/p&gt;
        &lt;/form&gt;
     &lt;div&gt;
     &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Result.html</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
     &lt;body&gt;
        &lt;table border = 1&gt;
           {% for key, value in result.items() %}
              &lt;tr&gt;
                 &lt;th&gt; {{ key }} &lt;/th&gt;
                 &lt;td&gt; {{ value }} &lt;/td&gt;
              &lt;/tr&gt;
           {% endfor %}
        &lt;/table&gt;
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now the result is displayed at result.html, i need that to be displayed on index.html. Please suggest, how to make this happen.</p>