I am trying to embed a bokeh application inside a django template by using the django_embed example as a reference point.
I would like the url path to the django application, however, to include a primary key which I thought should be easy enough to implement but I’m running into trouble.
Here’s what I’m doing.
In the urlpatterns I rewrite the path to sea_surface as follows:
That means that Django will extract that part <int:pk>of the URL, convert it to an int, and pass it as a variable named pk to the handler. Which means that handler necessarily must be able to accept having a parameter pk passed to it. But your current sea_surface handler does not:
Right, but the thing I don’t understand is why doing so results in a autoload.js 404 error. If I enter something like 127.0.0.1:8000/other/path/23/sea_surface in the browser, I get Not Found: /other/path/23/sea_surface/autoload.js
The script tag generated by server_document looks fine to me as it does include the pk value.
So I don’t understand why embedding the application doesn’t work when adding pk values to the url path.
As for the motivation for doing so, the bokeh applications will be run by signed-in users and will be unique to each user, so I want each application to have their own url address, that is my reasoning for using pk in the first place.
There is only one base URL for a Bokeh application. That is why inserting pk in to the Bokeh URL results in a 404. Bokeh does not know anything about the Django configuration at all, its routes are not affected by anything on the Django side. The call to server_document needs to use the one, unique, standard Bokeh app URL. If you need to pass additional information to a Bokeh app session, the current best way to do that is via HTTP request arguments. You can pass a Python dict to server_document via the arguments parameter. That will add HTTP requests arguments that can be accessed in the app code as described here:
in some upcoming releases it will be possible to send additional information in a JWT-like token as well.
Thank you Bryan for your reply. It certainly does help and I understand now that the issue I’m facing is more complicated than I anticipated. Now I am wondering what the best way to approach this issue in more general terms is, but I am creating a new topic to ask for help with that.