I have a flask application that is laid out as a few MethodViews.
On one of my MethodViews, I want to open a database connection before each request, and close it after the request, very similar to this.
I know how to use global @app.before_request and @app.teardown_request functions, but those will run for every single request. I want limited versions that will only run for the routes in a particular MethodView.
You could use a decorator, that would tag certain views as database dependent.
A runnable standalone example can be found here: https://gist.github.com/4424587