I'm building an API using Connexion, so I'm using app = connexion.FlaskApp(__name__)
instead of instead of Flask(__name__)
.
I want to add before_request
and after_request
handlers to open and close a database connection. However, since app
is a connexion.FlaskApp
object, those decorator methods don't exist.
@app.before_request
def before_request():
g.db = models.db
g.db.connection()
@app.after_request
def after_request():
g.db.close()
How can I use before_request
and other Flask methods when I'm using Connexion?