Flask Test: preprocess_request(), dispatch_request() Flask Test: preprocess_request(), dispatch_request() flask flask

Flask Test: preprocess_request(), dispatch_request()


I'm not an expert in Flask, so this answer might miss some points, but I think it's enough to help clarify your situation:

  • If a before_request function returns something else than None, it is taken as the view's response, so no more treatment happens, see preprocess_request's doc
  • process_response calls the after_request methods, it's called regardless of the response content (AFAIK)
  • As per the same doc linked above, I would say that rv is the first non-None result received from before_request, not the last, as as soon as a non-None is returned, the processing stops.

At a glance, I would say that this is the order of things:

  1. preprocess_request: call the before_request functions in order
  2. As soon as one of them returns something different than None, stop calling the remaining ones and jump to (4)
  3. dispatch_request: call the method associated to the routing rule
  4. make_response: prepare the Response object based on the previous result (here, rv)
  5. process_response: call the after_request functions with the Response object