Skip to content

Commit 277ebc7

Browse files
add support for root function in ui.run_with
1 parent 8b59679 commit 277ebc7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

nicegui/ui_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run(root: Optional[Callable] = None, *,
8383
You can call `ui.run()` with optional arguments.
8484
Most of them only apply after stopping and fully restarting the app and do not apply with auto-reloading.
8585
86-
:param root: root page function
86+
:param root: root page function (*added in version 3.0.0*)
8787
:param host: start server with this host (defaults to `'127.0.0.1` in native mode, otherwise `'0.0.0.0'`)
8888
:param port: use this port (default: 8080 in normal mode, and an automatically determined open port in native mode)
8989
:param title: page title (default: `'NiceGUI'`, can be overwritten per page)

nicegui/ui_run_with.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from contextlib import asynccontextmanager
22
from pathlib import Path
3-
from typing import Literal, Optional, Union
3+
from typing import Callable, Literal, Optional, Union
44

55
from fastapi import FastAPI
66
from fastapi.middleware.gzip import GZipMiddleware
@@ -14,6 +14,7 @@
1414

1515
def run_with(
1616
app: FastAPI, *,
17+
root: Optional[Callable] = None,
1718
title: str = 'NiceGUI',
1819
viewport: str = 'width=device-width, initial-scale=1',
1920
favicon: Optional[Union[str, Path]] = None,
@@ -33,6 +34,7 @@ def run_with(
3334
"""Run NiceGUI with FastAPI.
3435
3536
:param app: FastAPI app
37+
:param root: root page function (*added in version 3.0.0*)
3638
:param title: page title (default: `'NiceGUI'`, can be overwritten per page)
3739
:param viewport: page meta viewport content (default: `'width=device-width, initial-scale=1'`, can be overwritten per page)
3840
:param favicon: relative filepath, absolute URL to a favicon (default: `None`, NiceGUI icon will be used) or emoji (e.g. `'🚀'`, works for most browsers)
@@ -64,6 +66,7 @@ def run_with(
6466
show_welcome_message=show_welcome_message,
6567
cache_control_directives=cache_control_directives,
6668
)
69+
core.root = root
6770
storage.set_storage_secret(storage_secret)
6871
core.app.add_middleware(GZipMiddleware)
6972
core.app.add_middleware(RedirectWithPrefixMiddleware)

0 commit comments

Comments
 (0)