frontend.py 650 B

1234567891011121314151617
  1. from fastapi import FastAPI
  2. from nicegui import app, ui, context
  3. def init(fastapi_app: FastAPI) -> None:
  4. @ui.page('/show')
  5. async 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. app.add_static_files("/scripts", "scripts")
  11. ui.run_with(
  12. fastapi_app,
  13. storage_secret='pick your private secret here', # NOTE setting a secret is optional but allows for persistent storage per user
  14. )