Before and After Requests4:27 with Kenneth Love
We often need to do things at the beginning of a request or at the end of one, before the response is sent back. In our case now, we need to connect to the database on the way in, and disconnect from it on the way out. Luckily, Flask provides two handy decorators for this.
g- A global object that Flask uses for passing information between views and modules.
before_request- A decorator to mark a function as running before the request hits a view.
after_request- A decorator to mark a function as running before the response is returned.
You need to sign up for Treehouse in order to download course files.Sign up