From http://www.realpython.com/blog/python/python-web-applications-with-flask-part-ii/