Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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.
New Terms
-
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.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up