-
-
Notifications
You must be signed in to change notification settings - Fork 538
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extend fastapi example to use storage in run_with
- Loading branch information
Showing
1 changed file
with
10 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
from fastapi import FastAPI | ||
|
||
from nicegui import ui | ||
from nicegui import app, ui | ||
|
||
|
||
def init(app: FastAPI) -> None: | ||
def init(fastapi_app: FastAPI) -> None: | ||
@ui.page('/show') | ||
def show(): | ||
ui.label('Hello, FastAPI!') | ||
|
||
ui.run_with(app) | ||
# NOTE dark mode will be persistent for each user across tabs and server restarts | ||
ui.dark_mode().bind_value(app.storage.user, 'dark_mode') | ||
ui.checkbox('dark mode').bind_value(app.storage.user, 'dark_mode') | ||
|
||
ui.run_with( | ||
fastapi_app, | ||
storage_secret='pick your private secret here' # NOTE setting a secret is optional but allows for persistent storage per user | ||
) |