title: Flask: Redirection not working
body: <p>Below is my flask code</p>
  
  <pre><code>from datetime import datetime
  from logging import DEBUG
  from flask import Flask , render_template , url_for , request , redirect
  
  app = Flask ( __name__ )
  app.logger.setLevel ( DEBUG )
  
  bookmarks = [ ]
  
  
  def store_bookmarks (url):
   bookmarks.append ( dict (
      url=url ,
      user="rgen" ,
      date=datetime.utcnow ()
  
  ) )
  
  
  @app.route ( '/' )
  @app.route ( '/index' )
  def index ( ):
  # return "Hello World!"
   return render_template ( 'index.html' )
  
  
  @app.route('/add', methods=['GET', 'POST'])
  def add():
   if request.method=="POST":
      url=request.form['url']
      store_bookmarks(url)
      return redirect(url_for('index'))
  return render_template('add.html')
  
  
  if __name__ == '__main__':
   app.run ()
  </code></pre>
  
  <h1>base.html</h1>
  
  <pre><code> &lt;!doctype html&gt;
  &lt;!--[if lt IE 7]&gt;      &lt;html class="no-js lt-ie9 lt-ie8 lt-ie7" lang=""&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 7]&gt;         &lt;html class="no-js lt-ie9 lt-ie8" lang=""&gt; &lt;![endif]--&gt;
  &lt;!--[if IE 8]&gt;         &lt;html class="no-js lt-ie9" lang=""&gt; &lt;![endif]--&gt;
  &lt;!--[if gt IE 8]&gt;&lt;!--&gt; &lt;html class="no-js" lang=""&gt; &lt;!--&lt;![endif]--&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"&gt;
          &lt;title&gt;{% block title %}{% endblock %}&lt;/title&gt;
          &lt;meta name="description" content=""&gt;
          &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  
          &lt;link rel="stylesheet" href="{{ url_for('static', filename='css/normalize.min.css') }}"&gt;
          &lt;link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}" &gt;
  
          &lt;script src="../statoc/js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;!--[if lt IE 8]&gt;
              &lt;p class="browserupgrade"&gt;You are using an &lt;strong&gt;outdated&lt;/strong&gt; browser. Please &lt;a href="http://browsehappy.com/"&gt;upgrade your browser&lt;/a&gt; to improve your experience.&lt;/p&gt;
          &lt;![endif]--&gt;
  
          &lt;div class="header-container"&gt;
              &lt;header class="wrapper clearfix"&gt;
                  &lt;!-- &lt;h1 class="title"&gt;Welcome &lt;/h1&gt; --&gt;
                  &lt;a href="{{ url_for('index') }}"&gt;&lt;h1 class="title"&gt;Thermos&lt;/h1&gt;&lt;/a&gt;
                  &lt;nav&gt;
                      &lt;ul&gt;
                          &lt;li&gt;&lt;a href="#"&gt;Login&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href="#"&gt;Sign Up&lt;/a&gt;&lt;/li&gt;
                          &lt;li&gt;&lt;a href="{{ url_for('add') }}"&gt;Add URL&lt;/a&gt;&lt;/li&gt;
                      &lt;/ul&gt;
                  &lt;/nav&gt;
              &lt;/header&gt;
          &lt;/div&gt;
  
          &lt;div class="main-container"&gt;
              &lt;div class="main wrapper clearfix"&gt;
                {% block content %}
                  {% endblock %}
  
                  {% block sender %}
                  &lt;aside&gt;
                      &lt;h3&gt;aside&lt;/h3&gt;
                      &lt;p&gt;blach blag blah&lt;/p&gt;
                  &lt;/aside&gt;
  
                      {% endblock %}
  
              &lt;/div&gt; &lt;!-- #main --&gt;
          &lt;/div&gt; &lt;!-- #main-container --&gt;
  
          &lt;div class="footer-container"&gt;
              &lt;footer class="wrapper"&gt;
                  &lt;h3&gt;A Bookmark Project by Raja Genupula&lt;/h3&gt;
              &lt;/footer&gt;
          &lt;/div&gt;
  
          &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"&gt;&lt;/script&gt;
          &lt;script&gt;window.jQuery || document.write('&lt;script src="../static/js/vendor/jquery-1.11.2.min.js"&gt;&lt;\/script&gt;')&lt;/script&gt;
  
          &lt;script src="js/main.js"&gt;&lt;/script&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h1>add.html</h1>
  
  <pre><code>{% extends "base.html" %}
  
  {% block title %}
  Thermos -- Add a URL
  {% endblock %}
  
  {% block content %}
      &lt;section&gt;
          &lt;h1&gt;Add a new URL&lt;/h1&gt;
          &lt;form action="" method="post"&gt;
          &lt;article&gt;
              &lt;p&gt;
                  Plase enter your bookmark here: &lt;input type="text" name="url"&gt;&lt;/input&gt;
              &lt;/p&gt;
              &lt;p&gt;
                  &lt;button type="submit"&gt;Submit&lt;/button&gt;
              &lt;/p&gt;
          &lt;/article&gt;
          &lt;/form&gt;
      &lt;/section&gt;
  {% endblock %}
  
  {% block sender %}
  {% endblock %}
  </code></pre>
  
  <h1>index.html</h1>
  
  <pre><code>{% extends "base.html" %}
  {% block title %}
  Thermos -- Welcome
  {% endblock %}
  {% block content %}
                  &lt;article&gt;
                      &lt;header&gt;
                          &lt;h1&gt;Welcome&lt;/h1&gt;
                          &lt;p&gt;A Flask Project by Raja Genupula&lt;/p&gt;
                      &lt;/header&gt;
                      &lt;section&gt;
                          &lt;h2&gt;Title: {{ title }}&lt;/h2&gt;
                          &lt;p&gt;Text: {{ text }}&lt;/p&gt;
                      &lt;/section&gt;
                      &lt;section&gt;
                          &lt;h2&gt;article section h2&lt;/h2&gt;
                          &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sodales urna non odio egestas tempor. Nunc vel vehicula ante. Etiam bibendum iaculis libero, eget molestie nisl pharetra in. In semper consequat est, eu porta velit mollis nec. Curabitur posuere enim eget turpis feugiat tempor. Etiam ullamcorper lorem dapibus velit suscipit ultrices. Proin in est sed erat facilisis pharetra.&lt;/p&gt;
                      &lt;/section&gt;
                  &lt;/article&gt;
  
  {% endblock %}
  </code></pre>
  
  <p>I am trying to add a URL with 'add' function and once input received , I want to redirect back to Index page but after clicking 'submit' button I am getting HTTP 400 error message and debugging shows Bad syntax or invalid data as below</p>
  
  <pre><code>HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax.
  POST - http://127.0.0.1:5000/add
  </code></pre>
  
  <p>Dont know what I am missing here. </p>
  
  <p>Please help. </p>
  
  <p>Thank you.</p>