Functions
build_routes_by_name
1
tuple[Mapping[str, Route…
▼
Return ``(by_name, collisions)`` split from a list of routes.
``by_name`` hold…
build_routes_by_name
1
tuple[Mapping[str, Route…
▼
def build_routes_by_name(routes: list[Route]) -> tuple[Mapping[str, Route], dict[str, list[Route]]]
Return(by_name, collisions)split from a list of routes.
by_nameholds the first occurrence of each name (a stable read model
exposed viaMappingProxyType). Routes that share both nameand
path are HTTP method variants of the same URL (e.g. GETfrom
page.py plus POST from _actions.py) and are not collisions
—url_forreturns the same URL either way.
collisionsmaps any name claimed by routes at different paths to
every conflictingRoute — surfaced as a route_namescontract
issue.
Parameters
| Name | Type | Description |
|---|---|---|
routes |
list[Route] |
Returns
tuple[Mapping[str, Route], dict[str, list[Route]]]
resolve_url
3
str
▼
Reverse a named route to a URL path.
Path-param kwargs substitute into ``{brac…
resolve_url
3
str
▼
def resolve_url(routes_by_name: Mapping[str, Route], name: str, /, **params: Any) -> str
Reverse a named route to a URL path.
Path-param kwargs substitute into{braces}and are percent-encoded;
any remaining kwargs become a urlencoded query string.Nonevalues
in the query are skipped (Starlette convention).
Parameters
| Name | Type | Description |
|---|---|---|
routes_by_name |
Mapping[str, Route] |
|
name |
str |
|
**params |
Any |
Returns
str