|
@@ -17,10 +17,11 @@ def add_route(self, route: BaseRoute) -> None:
|
|
"""Route
|
|
"""Route
|
|
|
|
|
|
Adds a new `Starlette route <https://www.starlette.io/routing/>`_.
|
|
Adds a new `Starlette route <https://www.starlette.io/routing/>`_.
|
|
- Routed paths must start with a `'/'`. Also see `@ui.get <https://nicegui.io/#get_decorator>`_ and
|
|
|
|
- `ui.add_static_files <https://nicegui.io/#get_decorator>`_ for more convinient ways to deliver non-ui content.
|
|
|
|
|
|
+ Routed paths must start with a slash "/".
|
|
|
|
+ Also see `@ui.get <https://nicegui.io/#get_decorator>`_ and `ui.add_static_files <https://nicegui.io/#get_decorator>`_
|
|
|
|
+ for more convenient ways to deliver non-UI content.
|
|
|
|
|
|
- :param route: starlette route including a path and a function to be called
|
|
|
|
|
|
+ :param route: Starlette route including a path and a function to be called
|
|
"""
|
|
"""
|
|
globals.app.routes.insert(0, route)
|
|
globals.app.routes.insert(0, route)
|
|
|
|
|
|
@@ -31,7 +32,7 @@ def add_static_files(self, path: str, directory: str) -> None:
|
|
Makes a local directory available at the specified endpoint, e.g. `'/static'`.
|
|
Makes a local directory available at the specified endpoint, e.g. `'/static'`.
|
|
Do only put non-security-critical files in there, as they are accessible to everyone.
|
|
Do only put non-security-critical files in there, as they are accessible to everyone.
|
|
|
|
|
|
- :param path: string that starts with a '/'
|
|
|
|
|
|
+ :param path: string that starts with a slash "/"
|
|
:param directory: folder with static files to serve under the given path
|
|
:param directory: folder with static files to serve under the given path
|
|
"""
|
|
"""
|
|
add_route(None, Mount(path, app=StaticFiles(directory=directory)))
|
|
add_route(None, Mount(path, app=StaticFiles(directory=directory)))
|
|
@@ -40,13 +41,13 @@ def add_static_files(self, path: str, directory: str) -> None:
|
|
def get(self, path: str):
|
|
def get(self, path: str):
|
|
"""GET Decorator
|
|
"""GET Decorator
|
|
|
|
|
|
- Decorating a function with the `@ui.get` makes it available at the specified endpoint, e.g. `'/another/route/<id>'`.
|
|
|
|
|
|
+ Decorating a function with `@ui.get` makes it available at the specified endpoint, e.g. `'/another/route/<id>'`.
|
|
|
|
|
|
Path parameters can be passed to the request handler like with `FastAPI <https://fastapi.tiangolo.com/tutorial/path-params/>`_.
|
|
Path parameters can be passed to the request handler like with `FastAPI <https://fastapi.tiangolo.com/tutorial/path-params/>`_.
|
|
If type-annotated, they are automatically converted to `bool`, `int`, `float` and `complex` values.
|
|
If type-annotated, they are automatically converted to `bool`, `int`, `float` and `complex` values.
|
|
An optional `request` argument gives access to the complete request object.
|
|
An optional `request` argument gives access to the complete request object.
|
|
|
|
|
|
- :param path: string that starts with a '/'
|
|
|
|
|
|
+ :param path: string that starts with a slash "/"
|
|
"""
|
|
"""
|
|
*_, converters = compile_path(path)
|
|
*_, converters = compile_path(path)
|
|
|
|
|