Document required signature of before_request functions

Unless you happened to also read preprocess_request()'s docstring,
it wasn't not obvious that return values from these functions are treated as
response values.
This commit is contained in:
Chris Rebert 2015-02-05 12:38:34 -08:00
parent a45fce8496
commit eccee36964

View file

@ -1243,7 +1243,13 @@ class Flask(_PackageBoundObject):
@setupmethod
def before_request(self, f):
"""Registers a function to run before each request."""
"""Registers a function to run before each request.
The function will be called without any arguments.
If the function returns a non-None value, it's handled as
if it was the return value from the view and further
request handling is stopped.
"""
self.before_request_funcs.setdefault(None, []).append(f)
return f