'Registers a function to run before each request.
For example, this can be used to open a database connection, or to load
the logged in user from the session.
The function will be called without any arguments. If it returns a
non-None value, the value is handled as if it was the return value from
the view, and further request handling is stopped.'

@setupmethod
def before_request(self, f):

    self.before_request_funcs.setdefault(None, []).append(f)
    return f
