Skip to content

Extension URLs¤

Overview of all classes, functions, and other objects related to defining extension URLs.

Read more on Extensions.

URLRoute dataclass ¤

URLRoute(
    path: str,
    handler: Optional[URLRouteHandler] = None,
    children: Iterable[URLRoute] = list(),
    name: Optional[str] = None,
    extra: Dict[str, Any] = dict(),
)

Bases: object

See source code

Framework-agnostic route definition.

This is similar to Django's URLPattern object created with django.urls.path().

The URLRoute must either define a handler function or have a list of child routes children. If both are defined, an error will be raised.

Example:

URLRoute("/my/path", handler=my_handler, name="my_name", extra={"kwargs": {"my_extra": "my_value"}})

Is equivalent to:

django.urls.path("/my/path", my_handler, name="my_name", kwargs={"my_extra": "my_value"})

With children:

URLRoute(
    "/my/path",
    name="my_name",
    extra={"kwargs": {"my_extra": "my_value"}},
    children=[
        URLRoute(
            "/child/<str:name>/",
            handler=my_handler,
            name="my_name",
            extra={"kwargs": {"my_extra": "my_value"}},
        ),
        URLRoute("/other/<int:id>/", handler=other_handler),
    ],
)

Attributes:

children class-attribute instance-attribute ¤

children: Iterable[URLRoute] = field(default_factory=list)

extra class-attribute instance-attribute ¤

extra: Dict[str, Any] = field(default_factory=dict)

handler class-attribute instance-attribute ¤

handler: Optional[URLRouteHandler] = None

name class-attribute instance-attribute ¤

name: Optional[str] = None

path instance-attribute ¤

path: str

URLRouteHandler ¤

Bases: typing.Protocol

See source code

Framework-agnostic 'view' function for routes