InterviewSolution
| 1. |
Explain Application Context. |
|
Answer» During a request, CLI command, or other activity, the application context keeps track of application-level data. The current app and g proxies are used instead of passing the application around to each function. This is similar to The Request Context. The Request Context, which keeps track of request-level data during a request, is COMPARABLE to this. When a request context is pushed, it is accompanied by an application context. Purpose of Application Context: Aspects of the Flask application object, such as config, can be accessed via VIEWS and CLI commands. Importing the app instance into your project's modules, on the other hand, is prone to circular import difficulties. There will be no app instance to import when using the app factory pattern or developing REUSABLE blueprints or extensions. The application context in Flask overcomes this problem. Instead of referring to an app directly, you use the current_app proxy, which points to the application that is now handling the action. When handling a request, Flask automatically pushes an application context. current_app will be accessible to view functions, error handlers, and other functions that run during a request. Application Context LIFETIME: As needed, the application context is generated and removed. A Flask application pushes an application context and a request context when it starts handling a request. When the request is completed, the request context is displayed, followed by the application context. An application context USUALLY lasts the same amount of time as a request. |
|