Storing data per user/session #449
-
Hi, maybe this is a stupid question, but I am new to NiceGUI: If I store data in global variables then does this also work if several users are accessing the pages? So would the content in "content" be separated by user/session? from nicegui import app, ui
content = {}
@ui.page('/two')
def page_two():
ui.label("Yes" if content["s"].value else "No")
ui.link('back', '/')
@ui.page('/')
def main_page():
content["s"] = ui.switch('switch')
ui.link('next ', page_two)
ui.run() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Good question, @ulrichbi! |
Beta Was this translation helpful? Give feedback.
Good question, @ulrichbi!
No, the value of global variables like
content
is shared across all users and sessions.Here we show an example of how to access a
session
dictionary, which is a separate storage per session. But we noticed that this is not very convenient and we are currently thinking about a better approach. See #373 for a similar discussion.