问题
Hi I am developing a bokeh application to perform some analysis. I want to get the URL parameters from the server so I can decide which data to render in the application.
Currently I can route URLs like http://127.0.0.1:5006/bokeh/videos/?hello=1
with the following configuration, but is there a way I can get the GET parameters {'hello':'1'}
from the application?
@bokeh_app.route("/bokeh/analysis/")
@object_page("analysis")
def make_analysis():
app = AnalysisApp.create()
return app
回答1:
For Flask (which Bokeh server is built on), you'd access url parameters using:
from flask import request
@bokeh_app.route("/bokeh/analysis/")
@object_page("analysis")
def make_analysis():
args = request.args
app = AnalysisApp.create()
return app
(the request object gets added to the function scope by the app.route decorator)
回答2:
Easier way: a dict of (param name, value) is available in curdoc().session_context.request.arguments
.
For your URL http://127.0.0.1:5006/bokeh/videos/?hello=1
, it would give {'hello', '1'}
.
来源:https://stackoverflow.com/questions/32316959/get-url-parameters-for-bokeh-application