app.url_for

Page actions AI-ready formats and sharing
Open LLM text
Share with AI
Ask Claude Ask ChatGPT Ask Gemini Ask Copilot

URL reversal for named routes.

Builds a{name: Route}index at freeze time and turns names back into path strings at call time. Used byapp.url_for and the {{ url_for(...) }}template…

URL reversal for named routes.

Builds a{name: Route}index at freeze time and turns names back into path strings at call time. Used byapp.url_for and the {{ url_for(...) }} template global.

Design notes live indocs/rfcs/004-url-for.md.

app.url_for

Name Type Default Description
type
qualified_name
element_type
description
source_file
line_number
is_autodoc
autodoc_element
_autodoc_template
_autodoc_url_path
_autodoc_page_type
title
doc_content_hash

Symbols on this page

build_routes_by_name
function
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 Default Description
routes list[Route]
resolve_url
function
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 Default Description
routes_by_name Mapping[str, Route]
name str
**params Any

View source · /home/runner/work/chirp/chirp/site/../src/chirp/app/url_for.py:1