Attach a callback to a hook. Three hooks are currently implemented: before_request Executed once before each request. The request context is available, but no routing has happened yet. after_request Executed once after each re
(self, name, func)
| 620 | return dict((name, []) for name in self.__hook_names) |
| 621 | |
| 622 | def add_hook(self, name, func): |
| 623 | ''' Attach a callback to a hook. Three hooks are currently implemented: |
| 624 | |
| 625 | before_request |
| 626 | Executed once before each request. The request context is |
| 627 | available, but no routing has happened yet. |
| 628 | after_request |
| 629 | Executed once after each request regardless of its outcome. |
| 630 | app_reset |
| 631 | Called whenever :meth:`Bottle.reset` is called. |
| 632 | ''' |
| 633 | if name in self.__hook_reversed: |
| 634 | self._hooks[name].insert(0, func) |
| 635 | else: |
| 636 | self._hooks[name].append(func) |
| 637 | |
| 638 | def remove_hook(self, name, func): |
| 639 | ''' Remove a callback from a hook. ''' |