Skip to content

FastAPI @app.get inside NiceGUI page #507

Closed Answered by falkoschindler
Nikodemski2002 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, that's possible. But you need to handle the query parameter in the page function and pass it to content. Here is an example:

def content(success: bool) -> None:
    ui.markdown('### Home Page')
    if success:
        ui.label('Successfully logged in')

@ui.page('/home')
def home(success: bool) -> None:
    content(success)

Note that this example uses a label instead of ui.notify. To show a notification immediately after opening a page, we need to wait for the client connection. Therefore we add a client parameter and await its connected method. Then we can call content and the notification is successfully sent to the client:

from nicegui import Client

def content(success: bool) -> N…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Nikodemski2002
Comment options

Answer selected by Nikodemski2002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #505 on March 12, 2023 22:25.