title: Python Flask: Different render_template for Get and Post Methods Possible?
body: <p>I have a template (<code>index.html</code>) that I would like to display on <code>GET</code> and the same template, with a variable added, on <code>POST</code>.</p>
  
  <p>app.py:</p>
  
  <pre><code>from flask import Flask, render_template
  app = Flask(__name__)
  
  @app.route("/")
  def hello():
      return render_template("index.html")
  
  @app.route("/", methods=["POST"])
  def hello_():
      return render_template("index.html", string_="Success!")
  
  if __name__ == "__main__":
      app.run(host='0.0.0.0', port=4567)
  </code></pre>
  
  <p>index.html:</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript" src="/static/jquery.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
  
      &lt;button onclick="signIn();"&gt;Sign In&lt;/button&gt;
      &lt;h1&gt;{{ string_ }}&lt;/h1&gt;
  
      &lt;script&gt;
          function signIn() {
          var data = "data";
  
          $.ajax({
              type : "POST",
              data: JSON.stringify(data, null, '\t'),
              contentType: 'application/json',
              success: function(result) {
                  console.log(result);
                  }
                });
          }
      &lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>traceback:</p>
  
  <pre><code> * Running on http://0.0.0.0:4567/ (Press CTRL+C to quit)
  127.0.0.1 - - [11/Dec/2015 11:16:17] "GET / HTTP/1.1" 200 -
  127.0.0.1 - - [11/Dec/2015 11:16:17] "GET /static/jquery.js HTTP/1.1" 304 -
  127.0.0.1 - - [11/Dec/2015 11:16:21] "POST / HTTP/1.1" 200 -
  </code></pre>
  
  <p>I'm not receiving an error, but the variable <code>string_</code> isn't appearing in the template on <code>POST</code> (after I click the button).  It appears that the template I have set to render on <code>POST</code> isn't working.</p>
  
  <p>Is it possible to render a different template in Flask based on <code>request.method</code>?</p>