def close_db(e=None):
    """If this request connected to the database, close the
    connection.
    """
    db = g.pop("db", None)

    if db is not None:
        db.close()
If this request connected to the database, close the
    connection.
    
examples/tutorial/flaskr/db.py