title: Python/Flask Login form throws 500 error on IIS
body: <p>Due to my restrictions at work, I have to rely on hosting my webapp on <strong>IIS 7.5</strong>.
  I configured <em>IIS</em> to serve the application via <strong>wfastcgi.py</strong>.</p>
  
  <p>The issue is, that a login form, throws an <strong>HTTP 500</strong> error on IIS, when clicking on the login button. The site gets loaded without issue. Also, code works perfectly fine, when I am running it on the flask development server.</p>
  
  <p>I have an extended version of the code, with access to a sqlite DB.
  I was able to narrow down the issue to the login session creation part.
  I am not sure, whether the issue is about the way how <em>IIS</em> handles <em>POST</em> and <em>GET</em> requests with <em>wfastcgi.py</em>, or something else.</p>
  
  <p>Here's the simplified version of the code, which throws the same error:
  <strong>UPDATE</strong>: Changed the view functions to the proper return redirect.</p>
  
  <pre><code>import wiw_ad_controller as parser
  import sys
  from flask import Flask, flash, render_template, redirect, url_for, request, session, abort
  import os
  
  
  
  app = Flask(__name__)
  
  @app.route('/')
  @app.route('/index', methods=['GET', 'POST'])
  def index():
      if not session.get('logged_in'):
  
          return render_template('login.html')        
      else:
          return render_template('index.html')        
  
  
  @app.route('/login', methods=['POST'])
  def login():
      if request.form['username'] == 'admin' and request.form['password'] == 'admin':
          session['logged_in'] = True
          flash("Login was successfull")
      else:
          flash("Wrong password!")
      return redirect(url_for('index')) 
  
  
  @app.route('/search', methods=['GET','POST'])
  def lookup_data():
      if (session.get('logged_in')==True):
          if request.method == 'POST' or request.method == 'GET':
  
              if (request.form['gpn'] and request.form['gpn'].isdigit()):
  
                  #code removed - not needed
                  return render_template('fetched_data.html', user_wiw=user_wiw, user_ad=user_ad)
              else:
                  flash('Wrong ID')
              return index()
      return redirect(url_for('index')) 
  
  
  @app.route("/logout")   
  def logout():
      session['logged_in'] = False
      return redirect(url_for('index')) 
  
  
  @app.errorhandler(500)
  def internal_error(exception):
      app.logger.exception(exception)
      return render_template('500.html'), 500 
  
  
  @app.errorhandler(404)
  def internal_error(exception):
      app.logger.exception(exception)
      return render_template('404.html'), 404
  
  
  
  
  if __name__ == '__main__':
      app.secret_key=os.urandom(12)
      app.run(debug=True)
  </code></pre>