Login
Theme: Light Dark

What is the lifecycle of a single request in a web framework like Rails/Django?

Tagged:

Home - Quora Link

The biggest insight I had was that the controller is instantiated for every request. So the request comes in and is routed to a controller based on routes.rb. The controller makes a copy of itself and runs all the code it finds in the method it’s been routed to. That method may call other controller methods or helper or model methods, but at the end, it’s going to either have a prior render or redirect, or it’s going to look for a view to render. The view renders in the context of the controller, so instance variables set in the controller are available to the view.

So route -> controller -> view. If something is affecting the request / response, it’s doing it at one of those steps.