在 Bokeh 服务器应用程序中获取 JSON 请求

Obtain JSON request in Bokeh server application

我想将用户引导至由 Bokeh 服务器托管的页面以及一些元数据。例如,我可能想将用户定向到

http://my-server/my-page?var=value

然后我想在 Python 端的 Bokeh 服务器应用程序代码中获取 {'var': 'value'} 请求,以便我可以做出相应的响应。

这可能吗?如果是,怎么做?

Bokeh 核心开发人员将我指向此文档页面:

https://docs.bokeh.org/en/latest/docs/user_guide/server.html#accessing-the-http-request

特别是在文档对象上可用:

# request.arguments is a dict that maps argument names to lists of strings,
# e.g, the query string ?N=10 will result in {'N': [b'10']}

args = curdoc().session_context.request.arguments

try:
  N = int(args.get('N')[0])
except:
  N = 200