static_files¶
- litestar.static_files.create_static_files_router(path: str, directories: Sequence[PathType], file_system: AnyFileSystem | str | None = None, send_as_attachment: bool = False, html_mode: bool = False, name: str = 'static', after_request: AfterRequestHookHandler | None = None, after_response: AfterResponseHookHandler | None = None, before_request: BeforeRequestHookHandler | None = None, cache_control: CacheControlHeader | None = None, exception_handlers: ExceptionHandlersMap | None = None, guards: Sequence[Guard] | None = None, include_in_schema: bool | EmptyType = _EmptyEnum.EMPTY, middleware: Sequence[Middleware] | None = None, opt: Mapping[str, Any] | None = None, security: Sequence[SecurityRequirement] | None = None, tags: Sequence[str] | None = None, router_class: type[Router] = <class 'litestar.router.Router'>, allow_symlinks_outside_directory: bool = False) Router ¶
Create a router with handlers to serve static files.
- Parameters:
path¶ – Path to serve static files under
directories¶ – Directories to serve static files from
file_system¶ – The file system to load the file from. Instances of
BaseFileSystem
,fsspec.spec.AbstractFileSystem
,fsspec.asyn.AsyncFileSystem
will be used directly. If passed string, use it to look up the corresponding file system from theFileSystemRegistry
. If not given, the file will be loaded fromdefault
send_as_attachment¶ – Whether to send the file as an attachment
html_mode¶ – When in HTML: - Serve an
index.html
file from/
- Serve404.html
when a file could not be foundname¶ – Name to pass to the generated handlers
after_request¶ –
after_request
handlers passed to the routerafter_response¶ –
after_response
handlers passed to the routerbefore_request¶ –
before_request
handlers passed to the routercache_control¶ –
cache_control
passed to the routerexception_handlers¶ – Exception handlers passed to the router
guards¶ – Guards passed to the router
include_in_schema¶ – Include the routes / router in the OpenAPI schema
middleware¶ – Middlewares passed to the router
opt¶ – Opts passed to the router
security¶ – Security options passed to the router
tags¶ –
tags
passed to the routerrouter_class¶ – The class used to construct a router from
allow_symlinks_outside_directory¶ –
Allow serving files that link a path inside a base directory (as specified in ‘directories’) to a path outside it. This should be handled with caution, as it allows potentially unintended access to files outside the defined ‘directories’ via symlink chains.
See also