[Python] Build the multipage taipy application with login page

Discussão em 'Python' iniciado por Stack, Agosto 4, 2025.

  1. Stack

    Stack Membro Participativo

    After clicking the login button, the application does not redirect to the intended page, and no action appears to occur. It seems that the button click event is either not being handled correctly or the logic to navigate to the next page is missing or not functioning as expected.

    Below is the code details app.py

    # app.py
    from taipy.gui import Gui
    from pages.login_page import login_page, username, password, login_error, on_login_action
    from pages.overview_page import overview_page
    from pages.analysis_page import analysis_page

    # App state
    logged_in = False
    page = "login"

    # Pages dictionary with tgb pages
    pages = {
    "login": login_page,
    "overview": overview_page,
    "analysis": analysis_page
    }

    def before_page_display(state, page_name):
    if not state.logged_in and page_name != "login":
    state.page = "login"

    gui = Gui(pages=pages)

    gui.run(title="Secure Taipy App with Builder",
    port=5000,
    use_reloader=True,
    before_page_display=before_page_display)



    login_page.py

    # pages/login_page.py
    import taipy.gui.builder as tgb
    from taipy.gui import notify

    VALID_USERNAME = "admin"
    VALID_PASSWORD = "1234"

    username = ""
    password = ""
    login_error = ""

    def on_login_action(state):
    if state.username == VALID_USERNAME and state.password == VALID_PASSWORD:
    state.logged_in = True
    state.login_error = ""
    state.page = "overview"
    else:
    state.login_error = "Invalid username or password."
    notify(state, "error", state.login_error)


    with tgb.Page() as login_page:
    tgb.text(" Login", mode="md")
    with tgb.layout(columns="1 1 1"):
    tgb.text("Username")
    tgb.input(value="{username}")
    with tgb.layout(columns="1 1 1"):
    tgb.text("Password")
    tgb.input(value="{password}", password=True)
    tgb.button("Login", on_action=on_login_action)
    tgb.text("{login_error}", color="red")




    analysis_page.py

    # pages/analysis_page.py
    import taipy.gui.builder as tgb


    with tgb.Page() as analysis_page:
    tgb.text(" Analysis", mode="md")
    tgb.text("This is the analysis page content.")


    overview_page.py

    # pages/overview_page.py
    import taipy.gui.builder as tgb


    with tgb.Page() as overview_page:
    tgb.text(" Overview", mode="md")
    tgb.text("This is the overview page content.")



    Could you help identify the issue with this code and suggest the necessary changes to ensure that the login button functions as intended?

    Continue reading...

Compartilhe esta Página