A decorator to bind a function to a request URL. Example:: @app.route('/hello/ ') def hello(name): return 'Hello %s' % name The `` `` part is a wildcard. See :class:`Router` for syntax details. :par
(self,
path=None,
method='GET',
callback=None,
name=None,
apply=None,
skip=None, **config)
| 869 | if DEBUG: route.prepare() |
| 870 | |
| 871 | def route(self, |
| 872 | path=None, |
| 873 | method='GET', |
| 874 | callback=None, |
| 875 | name=None, |
| 876 | apply=None, |
| 877 | skip=None, **config): |
| 878 | """ A decorator to bind a function to a request URL. Example:: |
| 879 | |
| 880 | @app.route('/hello/<name>') |
| 881 | def hello(name): |
| 882 | return 'Hello %s' % name |
| 883 | |
| 884 | The ``<name>`` part is a wildcard. See :class:`Router` for syntax |
| 885 | details. |
| 886 | |
| 887 | :param path: Request path or a list of paths to listen to. If no |
| 888 | path is specified, it is automatically generated from the |
| 889 | signature of the function. |
| 890 | :param method: HTTP method (`GET`, `POST`, `PUT`, ...) or a list of |
| 891 | methods to listen to. (default: `GET`) |
| 892 | :param callback: An optional shortcut to avoid the decorator |
| 893 | syntax. ``route(..., callback=func)`` equals ``route(...)(func)`` |
| 894 | :param name: The name for this route. (default: None) |
| 895 | :param apply: A decorator or plugin or a list of plugins. These are |
| 896 | applied to the route callback in addition to installed plugins. |
| 897 | :param skip: A list of plugins, plugin classes or names. Matching |
| 898 | plugins are not installed to this route. ``True`` skips all. |
| 899 | |
| 900 | Any additional keyword arguments are stored as route-specific |
| 901 | configuration and passed to plugins (see :meth:`Plugin.apply`). |
| 902 | """ |
| 903 | if callable(path): path, callback = None, path |
| 904 | plugins = makelist(apply) |
| 905 | skiplist = makelist(skip) |
| 906 | |
| 907 | def decorator(callback): |
| 908 | if isinstance(callback, basestring): callback = load(callback) |
| 909 | for rule in makelist(path) or yieldroutes(callback): |
| 910 | for verb in makelist(method): |
| 911 | verb = verb.upper() |
| 912 | route = Route(self, rule, verb, callback, |
| 913 | name=name, |
| 914 | plugins=plugins, |
| 915 | skiplist=skiplist, **config) |
| 916 | self.add_route(route) |
| 917 | return callback |
| 918 | |
| 919 | return decorator(callback) if callback else decorator |
| 920 | |
| 921 | def get(self, path=None, method='GET', **options): |
| 922 | """ Equals :meth:`route`. """ |