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)
| 660 | return dict((name, []) for name in self.__hook_names) |
| 661 | |
| 662 | def add_hook(self, name, func): |
| 663 | """ Attach a callback to a hook. Three hooks are currently implemented: |
| 664 | |
| 665 | before_request |
| 666 | Executed once before each request. The request context is |
| 667 | available, but no routing has happened yet. |
| 668 | after_request |
| 669 | Executed once after each request regardless of its outcome. |
| 670 | app_reset |
| 671 | Called whenever :meth:`Bottle.reset` is called. |
| 672 | """ |
| 673 | if name in self.__hook_reversed: |
| 674 | self._hooks[name].insert(0, func) |
| 675 | else: |
| 676 | self._hooks[name].append(func) |
| 677 | |
| 678 | def remove_hook(self, name, func): |
| 679 | """ Remove a callback from a hook. """ |