Skip to main content

FletStaticFiles

Serve Flet app static files.

Parameters:

  • assets_dir (str | None, default: None) - Path to app's assets directory. A relative path is resolved against the current working directory.
  • app_name (str | None, default: None) - PWA application name.
  • app_short_name (str | None, default: None) - PWA application short name.
  • app_description (str | None, default: None) - PWA application description.
  • web_renderer (WebRenderer, default: WebRenderer.AUTO) - Type of web renderer, as a WebRenderer or its value, e.g. "canvaskit".
  • route_url_strategy (RouteUrlStrategy, default: RouteUrlStrategy.PATH) - Routing URL strategy, as a RouteUrlStrategy or its value, e.g. "hash".
  • no_cdn (bool, default: False) - Whether not load CanvasKit, Pyodide, and fonts from CDN.
  • websocket_endpoint_path (str | None, default: None) - Path of Flet app WebSocket handler. A path without a leading / is resolved against the app mount path. Defaults to ws.

Inherits: fastapi.staticfiles.StaticFiles

Properties

Methods

  • lookup_path - Resolve a static file path, with SPA fallback for client-side routes.

Properties​

font_manifest_jsoninstance-attribute​

indexinstance-attribute​

manifest_jsoninstance-attribute​

route_url_strategyproperty​

route_url_strategy: RouteUrlStrategy

The route URL strategy written into the served index.html: the route_url_strategy argument, or FLET_WEB_ROUTE_URL_STRATEGY if set.

Methods​

lookup_path​

lookup_path(
    path: str,
) -> tuple[str, os.stat_result | None]

Resolve a static file path, with SPA fallback for client-side routes.

With the path route URL strategy, route-like paths (no extension, or .html) that don't match a file fall back to index.html so the Flutter client can handle routing. Asset-like paths (any other extension) resolve to a real 404.

With the hash strategy, routes live in the URL fragment and never reach the server, so there is no fallback: any path that doesn't match a file resolves to a real 404 (with a 404.html from the assets directory as its body, if there is one), while the mount root still serves index.html.

Parameters:

  • path (str) - Requested path, relative to the mounted static root (e.g. "about", "sample.json").

Returns:

  • tuple[str, os.stat_result | None] - A (full_path, stat_result) tuple. When stat_result is None, Starlette responds with 404.