I’d like to set some cookies to store some simple settings in the browser. I can see that several modules in
set_cookie methods, but im struggling to figure out how to access those dochandler objects, and havent had luck instantiating one correctly.
I am using
pn.serve(template) and can see existing cookies with
pn.state.cookies. I can also see that that comes from
pn.state.curdoc.request.cookies, which i havent been able to trace back any further, i was hoping it was coming from one of the
I tried several things and i could not do it. I finally set up a cookie with document.cookie = ‘’
import panel as pn
print ('cookies', pn.state.cookies)
print ('header', pn.state.headers)
print ('curdoc', pn.state.curdoc.session_context._server_context._application_context)
session_context = getattr(pn.state.curdoc, 'session_context', None)
# session_context._request['Cookie'] = 'asderer'
print ('#######', session_context._request.__dict__)
print ('acces token', pn.state.access_token)
html = pn.pane.HTML('')
html.object = """
document.cookie = "custom_cookie=custom_value; Expires=Fri, 8 Jul 2022 14:28:00 GMT, SameSite=None; Secure";
return pn.Row('Hello world', html)
Thanks for the reply. Glad i wasn’t missing something obvious. Your solution seems like a good workaround.
I ended up giving up and relying on a local file, which works for my application but isn’t as useful as a cookie could be.
I think if one sets pn.state.cookies, it should be the right way, but it seems there are two cookies, this and the other in the proxy object called Cookie (which is read-only). Maybe it has to be reported as a bug.
Yea copy. When i tried setting the
pn.state.cookies, it didnt seem to propagate to the browser.