小编Ada*_*dam的帖子

Python Dash Basic Auth - 在应用程序中获取用户名

我目前正在制作一个 Dash 应用程序,它会根据用户权限显示不同的布局,所以我希望能够识别注册的用户。我正在使用基本身份验证,我更改了 dash_auth/basic_auth.py 中的一些行:原始:

username_password_utf8 = username_password.decode('utf-8')
username, password = username_password_utf8.split(':')
Run Code Online (Sandbox Code Playgroud)

到:

username_password_utf8 = username_password.decode('utf-8')
username, password = username_password_utf8.split(':')
self._username = username
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我尝试使用来自 auth 的 _username 属性时,我收到了:AttributeError: 'BasicAuth' object has no attribute '_username' 错误。

app.layout = html.Div(
    html.H3("Hello " + auth._username)
)
Run Code Online (Sandbox Code Playgroud)

我知道在授权检查之前已经处理了 Dash 应用程序,但我不知道在哪里实现根据用户名更改布局的回调。如何在 Dash 应用程序中获取用户名?

python authentication web-applications callback plotly-dash

8
推荐指数
1
解决办法
5427
查看次数