【问题标题】:Dash username element 'object provided as children' error破折号用户名元素“作为孩子提供的对象”错误
【发布时间】:2021-11-10 19:12:47
【问题描述】:

我有一个简单的 Dash 导航栏,在用户登录时显示用户名

但是,当我单击用户名时,它会显示一个转瞬即逝的错误(在 an object was provided as children instead of a component, string, or number (or list of those)。显示错误后,再次单击用户名时,它会正确重定向到页面。

我有一个相同的登录页面回调机制,它工作得很好。我不明白是什么导致了这个短暂的错误,以及为什么它在第二次尝试时仍然导航到页面。

可能出了什么问题,我该如何解决?

header = dbc.Navbar(
    dbc.Container(
        [
            dbc.Nav(
                [
                    dbc.NavItem(dbc.NavLink('user-name',id='user-name',href='Profile')), #displays the error when clicked
                    dbc.NavItem(dbc.NavLink('login', id='user-action', href='Login')),
                ]
            )
        ],
    ),
)

#broken callback
@app.callback(
    [Output('user-name', 'children'),
     Output('user-name', 'href'),
     ],
    [Input('page-content', 'children')])
def profile_link(content):
    if current_user.is_authenticated:
        return str(current_user.first),'/profile'
    else:
        return '',''

工作回调:

@app.callback(
    [Output('user-action', 'children'),
     Output('user-action', 'href'),
     ],
    [Input('page-content', 'children')])
def user_logout(input1):
    if current_user.is_authenticated:
        return 'logout', '/logout'
    else:
        return 'login', '/login'

【问题讨论】:

    标签: python flask plotly-dash


    【解决方案1】:

    修复结果非常简单 - 只是在导航链接中添加了一个“外部链接”标签

    dbc.NavItem(dbc.NavLink('user-name',id='user-name',href='/profile',external_link=True))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      • 1970-01-01
      • 2011-01-18
      • 2020-11-09
      • 2014-05-14
      • 2012-08-31
      相关资源
      最近更新 更多