InterviewHubPRO
Section Overview
Q50

Question 50 of 65

Part 4: Web Frameworks, APIs & FastAPI (41 - 55)

77%
Python & FastAPI•Part 4: Web Frameworks, APIs & FastAPI (41 - 55)

Flask Contexts: Application vs Request Context:

In Simple Words:

  • Application Context (current_app, g): Bound to the application instance; stores DB connections and global app configs.
  • Request Context (request, session): Bound to the current incoming HTTP request; stores cookies, headers, and form data.
python
from flask import request, g

@app.before_request
def load_user():
    g.user_id = request.headers.get("X-User-ID")