title: Gunicorn 500'ing on POST to Flask app
body: <p>Here's the Flask app:</p>
  
  <pre><code>from flask import Flask, request, render_template, redirect, url_for, flash
  app = Flask(__name__)
  
  @app.route('/')
  def index():
      return render_template('index.html')
  
  @app.route('/contact', methods = ['POST'])
  def contact():
      if request.method == 'POST':
          name = request.form['name']
          email = request.form['email']
          message = request.form['message']
  
          flash(name)
          flash(email)
          flash(message)
  
      return redirect(url_for('index'))
  
  if __name__ == '__main__':
      app.debug = True
      app.secret_key='a;sldfjka;oeiga;lbneas; biaweag'
      app.run()
  </code></pre>
  
  <p>Here's the template I'm using:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
  
      &lt;body&gt; 
          &lt;form action="/contact" method="post"&gt;
              &lt;input type="text" name="name" /&gt;
              &lt;input type="text" name="email" /&gt;
              &lt;textarea name="message"&gt; &lt;/textarea&gt;
              &lt;input type="submit" /&gt;
          &lt;/form&gt; 
          &lt;ul&gt;
          {% for message in get_flashed_messages() %}
              &lt;li&gt;&lt;h3&gt; {{ message }} &lt;/h3&gt;&lt;/li&gt;
          {% endfor %}
          &lt;/ul&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And here's the <code>gunicorn</code> command line I use to serve it:</p>
  
  <pre><code>gunicorn --error-logfile err.log --access-logfile access.log \
  --log-level debug -b 127.0.0.1:5000 --debug -w 4 wsgi:app
  </code></pre>
  
  <p>It serves the GET request for the template just fine.  However, when I actually POST the form, it 500's out.  Here's the response headers:</p>
  
  <pre><code>HTTP/1.1 500 INTERNAL SERVER ERROR
  Server: gunicorn/0.17.2
  Date: Thu, 21 Mar 2013 21:57:25 GMT
  Connection: close
  Content-Type: text/html
  Content-Length: 291
  </code></pre>
  
  <p>Here's what shows up in the gunicorn logs:</p>
  
  <pre><code>==&gt; err.log &lt;==
  2013-03-21 17:12:38 [10092] [DEBUG] POST /contact
  
  ==&gt; access.log &lt;==
  "127.0.0.1 - - [21/Mar/2013:17:12:38] "POST /contact HTTP/1.1" 500 291 \
  "http://localhost:5000/" "Mozilla/5.0 (X11; Linux x86_64; rv:19.0) \
  Gecko/20100101 Firefox/19.0"
  </code></pre>
  
  <p>Works fine when I serve it using Flask's built in dev server.  </p>
  
  <p>Mah brain tells me that this is something reeeeally simple that I'm just missing.  Guh.</p>