Method: flask.scaffold.Scaffold.route
Calls: 329, Exceptions: 0, Paths: 1Back
Path 1: 329 calls (1.0)
'/' (152) '/error' (22) '/abort' (8) '/home' (7) '/bar' (6) '/forbidden' (5) '/custom' (5) '/json' (4) '/raise' (4) '/set' (3)
{} (261) dict (57) {'subdomain': 'foo'} (2) {'endpoint': 'bar'} (2) {'endpoint': '123'} (2) {'subdomain': '
Scaffold.route.
1@setupmethod
2 def route(self, rule: str, **options: t.Any) -> t.Callable[[T_route], T_route]:
3 """Decorate a view function to register it with the given URL
4 rule and options. Calls :meth:`add_url_rule`, which has more
5 details about the implementation.
6
7 .. code-block:: python
8
9 @app.route("/")
10 def index():
11 return "Hello, World!"
12
13 See :ref:`url-route-registrations`.
14
15 The endpoint name for the route defaults to the name of the view
16 function if the ``endpoint`` parameter isn't passed.
17
18 The ``methods`` parameter defaults to ``["GET"]``. ``HEAD`` and
19 ``OPTIONS`` are added automatically.
20
21 :param rule: The URL rule string.
22 :param options: Extra options passed to the
23 :class:`~werkzeug.routing.Rule` object.
24 """
25
26 def decorator(f: T_route) -> T_route:
27 endpoint = options.pop("endpoint", None)
28 self.add_url_rule(rule, endpoint, f, **options)
29 return f
30
31 return decorator