1.

Explain Django Response lifecycle?

Answer»

Whenever a request is MADE to a web page, Django creates an HttpRequest object that contains METADATA about the request. After that Django loads the particular view, PASSING the HttpRequest as the first argument to the view function. Each view will be returning an HttpResponse object.
On the big picture following steps occur when a request is RECEIVED by Django:

  1. First of the Django settings.py file is loaded which also contain various middleware classes (MIDDLEWARES)
  2. The middlewares are also executed in the ORDER in which they are mentioned in the MIDDLEWAREST
  3. From here on the request is now moved to the URL Router, who simply gets the URL path from the request and tries to map with our given URL paths in the urls.py. 
  4. As soon as it has mapped, it will call the equivalent view function, from where an equivalent response is generated
  5. The response also passes through the response middlewares and send back to the client/browser.


Discussion

No Comment Found