From eccee36964832577aad8d8a3108b7f39958ba8b0 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 5 Feb 2015 12:38:34 -0800 Subject: [PATCH] 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. --- flask/app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/flask/app.py b/flask/app.py index 1aac95eb..bd721a4d 100644 --- a/flask/app.py +++ b/flask/app.py @@ -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