Web Framework Internals interview question · Most asked

Walk through the Django request lifecycle.

Summary

WSGI/ASGI handler builds HttpRequest → MIDDLEWARE in order (request phase) → URL resolver → process_view hooks → view → process_exception on errors or template response rendering → MIDDLEWARE in reverse (response phase) → request_finished signal.

Longer Answer

Middleware that uses request.user must come after AuthenticationMiddleware, which needs SessionMiddleware. process_view can short-circuit before the view (CSRF does).

Key Points

  • Middleware down, resolver, process_view, view.
  • process_exception and template rendering.
  • Middleware up, request_finished.
  • Ordering dependencies matter.

Deep dive: Request Lifecycle: The Django Request Lifecycle and Middleware Order

Explanation

What interviewers look for

Correct order including process_view and ordering dependencies.

More most-asked Web Framework Internals questions

← All Web Framework Internals questions