Skip to content

FastApi and nicegui #2223

Answered by hasansezertasan
markospy asked this question in Q&A
Dec 21, 2023 · 2 comments · 9 replies
Discussion options

You must be logged in to vote

I believe this is quite simple:

from fastapi import FastAPI
from nicegui import app as nicegui_app, ui

app = FastAPI()


@app.get('/')
def read_root():
    return {'Hello': 'World'}


# Register a page with a custom path
@ui.page('/show')
def show():
    # Your UI code goes here
    ui.label('Hello, FastAPI!')
    # Some bindings
    ui.dark_mode().bind_value(nicegui_app.storage.user, 'dark_mode')
    ui.checkbox('dark mode').bind_value(nicegui_app.storage.user, 'dark_mode')


# Integrate with your FastAPI Application
ui.run_with(
    app=app,
    storage_secret='pick your private secret here',
)

storage_secret is based on SessionMiddleware...

Replies: 2 comments 9 replies

Comment options

You must be logged in to vote
9 replies
@markospy
Comment options

@rodja
Comment options

@hasansezertasan
Comment options

Answer selected by markospy
@markospy
Comment options

@markospy
Comment options

@hasansezertasan
Comment options

@markospy
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants