You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am trying to create a minimal app that mounts another app. I have created this sample code:
fromfasthtml.commonimportA, FastHTML, Mount, P, fast_app, serve, uri, Titled# pylint: disable=no-name-in-modulemount_app, mount_rt=fast_app()
@mount_rt("/")defhome(session: dict):
""" Home page. """returnTitled(
"Mount demo",
P(f"Session value is {session.get('foo')}"),
)
app: FastHTMLapp, rt=fast_app(
debug=True,
live=True,
secret_key="xxxxxxx",
routes=[
Mount("/subapp", mount_app, name="subapp"),
],
)
@rt("/set", name="set_session")defset_session(session):
""" Set session. """session.setdefault("foo", 0)
session["foo"] +=1returnTitled("Set", P(f"Session set to {session.get('foo')}; click here to ", A("Get", link=uri("home"))))
@rt("/", name="home")defget_session(session):
""" Get session. """session.setdefault("foo", 0)
returnTitled("Get", P(f"Session: {session.get('foo')}; click here to ", A("Set", link=uri("set_session")), "; go to ", A("subapp", link=uri("subapp:home"))))
serve()
When I access http://127.0.0.1:5001, the cookie is not set, and default value is 0. If I click on "Set" to change its value, and click back to "Get", I get the new value (1). But if click to go to /subapp, the session value is missing. How can I make the session to be shared between the main app and the mounted apps?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I am trying to create a minimal app that mounts another app. I have created this sample code:
When I access http://127.0.0.1:5001, the cookie is not set, and default value is 0. If I click on "Set" to change its value, and click back to "Get", I get the new value (1). But if click to go to /subapp, the session value is missing. How can I make the session to be shared between the main app and the mounted apps?
Beta Was this translation helpful? Give feedback.
All reactions