Taipy 有没有任何路线机制或任何替代品?

问题描述 投票:0回答:1

我是 Taipy 的新手。我想做一个简单的登录流程:默认页面是登录页面,登录成功后进入主页面。 但 Taipy 官方文档页面只有单页/多页介绍。

Taipy 有没有什么解决方案可以更换?

routes taipy
1个回答
0
投票

您可以在这里看到一个简单的登录示例。页面已构建且不受保护。您可以使用 partials 将页面从空页面更改为隐藏内容的样子。

认证、授权、受保护页面等机制直接集成到Taipy Enterprise中。

from taipy.gui import Gui, notify


login_open = True
username = ''
password = ''


dialog_md = """
<|{login_open}|dialog|title=Login|labels=Create account|on_action=create_account|width=30%|
**Username**
<|{username}|input|label=Username|class_name=fullwidth|>

**Password**
<|{password}|input|password|label=Password|class_name=fullwidth|>

<br/>
<|Sign in|button|class_name=fullwidth plain|on_action=login|>
|>
"""


def create_account(state):
    notify(state, "info", "Creating account...")
    # Put your own logic to create an account
    # Maybe, by opening another dialog
    state.username = "Taipy"
    state.password = "password"
    notify(state, "success", "Account created!")


def login(state):
    # Put your own authentication system here
    if state.username == "Taipy" and state.password == "password":
        state.login_open = False
        notify(state, "success", "Logged in!")
    else:
        notify(state, "error", "Wrong username or password!")


pages = {"/": dialog_md,
         "Home": "# Taipy application"}

if __name__ == "__main__":
    Gui(pages=pages).run()

© www.soinside.com 2019 - 2024. All rights reserved.