Flask Application And Request Contexts

Posted on with tags: flask / python

Application and request contexts are difficult concepts in Flask. They are easy for programmers to use, but they are not easy to understand. The implementation of those concepts is complicated.

Patrick Kennedy wrote a long article on testdriven.io website regarding this topic. He also had a presentation on the same topic for FlaskCon2020. Both article and presentation are very good. The article also discusses the request-response cycle in more details than other articles.

Article - Deep Dive into Flask’s Application and Request Contexts

Presentation on Youtube - Demystifying Flask’s Application and Request Contexts with pytest

The article above needs some background knowledge on Python threading. The realpython website has an excellent article on threading by Jim Anderson. The article covers most threading topics in the official Python threading documentation.

Realpython.com - An Intro to Threading in Python

Python.org - Threading - Thread-based Parallelism

Realpython.com - Speed Up Your Python Program With Concurrency

The Flask documentation has one page for application context and another page for request context. The documentation pages are not written in a tutorial style and are difficult understand if you do not read the code, but they are good and accurate.

Flask documentation page - The Application Context

Flask documentation page - The Request Context