Start here. This is the direct spoken answer to practice first.
Overview
Middleware order determines which request context exists and which responses each layer can observe.
Django middleware wraps the next layer like nested functions. Request processing enters middleware from top to bottom, then the response comes back from bottom to top. A middleware can return a response without calling the next layer, so lower middleware and the view will not run. Dependencies between layers matter; for example, session middleware must establish session state before authentication middleware uses it.