frontend.py 695 B

12345678910111213141516171819
  1. from fastapi import FastAPI
  2. from nicegui import app, ui
  3. def init(fastapi_app: FastAPI) -> None:
  4. @ui.page('/')
  5. def show():
  6. ui.label('Hello, FastAPI!')
  7. # NOTE dark mode will be persistent for each user across tabs and server restarts
  8. ui.dark_mode().bind_value(app.storage.user, 'dark_mode')
  9. ui.checkbox('dark mode').bind_value(app.storage.user, 'dark_mode')
  10. ui.run_with(
  11. fastapi_app,
  12. mount_path='/gui', # NOTE this can be omitted if you want the paths passed to @ui.page to be at the root
  13. storage_secret='pick your private secret here', # NOTE setting a secret is optional but allows for persistent storage per user
  14. )