{"record":{"id":"dde7f394cd9ccec4","repo":"tiangolo/fastapi","slug":"no-route-exists-for-name-name-and-params-par","errorCode":null,"errorMessage":"No route exists for name \"{name}\" and params \"{params}\".","messagePattern":"No route exists for name \"(.+?)\" and params \"(.+?)\"\\.","errorType":"exception","errorClass":"NoMatchFound","httpStatus":null,"severity":"error","filePath":"fastapi/routing.py","lineNumber":2100,"sourceCode":"            return Match.PARTIAL, child_scope\n        return Match.FULL, child_scope\n\n    def _get_frontend_path(self, path: str, route_path: str) -> str | None:\n        if path == \"/\":\n            return route_path.lstrip(\"/\")\n        if route_path == path:\n            return \"\"\n        prefix = path + \"/\"\n        if route_path.startswith(prefix):\n            return route_path[len(prefix) :]\n        return None\n\n    async def handle(self, scope: Scope, receive: Receive, send: Send) -> None:\n        response = await self.app.get_response_for_scope(scope)\n        await response(scope, receive, send)\n\n    def url_path_for(self, name: str, /, **path_params: Any) -> URLPath:\n        raise NoMatchFound(name, path_params)\n\n\nclass _FrontendRouteGroup(BaseRoute):\n    def __init__(\n        self,\n        *,\n        dependencies: Sequence[params.Depends] | None = None,\n        dependency_overrides_provider: Any | None = None,\n    ) -> None:\n        self.routes: list[_FrontendRoute] = []\n        self.dependencies = list(dependencies or [])\n        self.dependency_overrides_provider = dependency_overrides_provider\n        (\n            self.dependant,\n            _,\n            self._embed_body_fields,\n        ) = _build_dependant_with_parameterless_dependencies(\n            path=\"\",","sourceCodeStart":2082,"sourceCodeEnd":2118,"githubUrl":"https://github.com/tiangolo/fastapi/blob/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/fastapi/routing.py#L2082-L2118","documentation":"`_FrontendRoute.url_path_for` (fastapi/routing.py:2100) always raises `NoMatchFound(name, path_params)`. Frontend static routes are not named and do not support reverse URL generation. During URL reversal (`app.url_path_for` / `request.url_for`), FastAPI iterates all routes and asks each to resolve the name; a frontend route answering NoMatchFound means 'I don't match, try the next'. The user only sees this propagate if NO route matches the requested name.","triggerScenarios":"Calling `app.url_path_for('nonexistent')` or `request.url_for('typo_name', **params)` where no registered path operation has that `name`. The frontend route participates in the search and declines via NoMatchFound, but the final raised exception originates from the last route (often a frontend route) that was tried.","commonSituations":"Renaming a path operation without updating calls to `url_path_for`. Using a name that was never set (default name is the function name). Typo in the name string. Calling `url_for` from a template with stale names after refactoring.","solutions":["Verify the name exists on a path operation: `@app.get('/items/{id}', name='get_item')`.","Use the exact `name` (default is the endpoint function's `__name__`).","Search the codebase for `name='...'` to confirm the registered name before calling `url_path_for`."],"exampleFix":"// before\nurl = request.url_for('getitem', id=5)  # wrong name\n// after\n@app.get('/items/{id}', name='getitem')\nasync def getitem(id: int): ...\nurl = request.url_for('getitem', id=5)","handlingStrategy":"validation","validationCode":"from fastapi.routing import compile_path\n\ndef route_name_exists(app, name: str) -> bool:\n    return any(getattr(r, 'name', None) == name for r in app.routes)\n\nif not route_name_exists(app, 'get_item'):\n    raise ValueError('no route named get_item; fix the name before url_path_for')\nurl = app.url_path_for('get_item', id=5)","typeGuard":"def is_known_route_name(app, name: object) -> bool:\n    return isinstance(name, str) and any(getattr(r, 'name', None) == name for r in app.routes)","tryCatchPattern":"from fastapi.exceptions import NoMatchFound\n\ntry:\n    url = app.url_path_for('maybe_name', id=5)\nexcept NoMatchFound:\n    url = None  # graceful fallback","preventionTips":["Define route names as module constants and reuse them at lookup sites.","Add a startup test asserting every url_path_for call resolves.","Avoid reversing against the default function name; set explicit name=."],"tags":["fastapi","routing","url-reversal","frontend-routing"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}