How to Bokeh serve + Django

I am trying to study the django_embed example. I also followed the instructions of ejprinz. However, all of the following environments got different kinds of the following errors

  1. bokeh-1.4.0 + panel-0.8.3 + Django 3.2 + django-param 0.1.10
    => File “C:\Users\yvechang\webapps\virtualenv\django_embed\lib\site-packages\django\apps\”, line 38, in init
    raise ImproperlyConfigured(
    django.core.exceptions.ImproperlyConfigured: The app label ‘bokeh.server.django’ is not a valid Python identifier.

  2. bokeh-1.4.0 + panel-0.8.3 + Django 2.2 + django-param 0.1.10
    =>File “”, line 991, in find_and_load
    from bokeh.server.django import autoload, directory, document, static_extensions
    ImportError: cannot import name ‘static_extensions’ from ‘bokeh.server.django’ (C:\Users\yvechang\webapps\virtualenv\django_embed\lib\site-packages\bokeh\server\django_init
    File “”, line 975, in _find_and_load_unlocked

@yvechang For starters, if you are going to run with old major versions of Bokeh you definitely need to look at the example code that is specific and appropriate for that version. New features are continually added, and example code is updated to use them. It’s common and expected that the latest examples don’t work with old versions of Bokeh, because the latest versions of examples use features that don’t exist in old Bokeh versions.[1]

Here is the code for that same example, that was published with version 1.4

bokeh/examples/howto/server_embed/django_embed at 1.4.0 · bokeh/bokeh · GitHub

  1. In this case, support for package relative imports like static_extensions was a feature only added in Bokeh 2.0 ↩︎

Hi Bryan,
I had replaced all files to version 1.4. However, the followinf error occurred:

raise ImproperlyConfigured(django.core.exceptions.ImproperlyConfigured: The app label ‘bokeh.server.django’ is not a valid Python identifier.

If I changed the line 41 in into

name = 'bokeh.server.django'
    label = 'bokeh_server_django'

Then, the following error occurred:
No installed app with label ‘bokeh.server.django’. Did you mean ‘bokeh_server_django’?

Does I missed updating something else?

@yvechang I actually am not really going to be able to help. I haven’t used Django personally in more than 10 years, so I am really no kind of expert at all on what those Django errors signify. The only thing that comes to mind is that maybe your current Django version is also too new. Hopefully someone else in the forum may have more relevant experience.

OK, I see. I just downgrade django to version 2.2, 2.01, 1.11. Still got fails. Maybe I should give up using bokeh to solve my project. Thank you for your kindly help!

@yvechang if you very specifically need the Bokeh server integration with Django, then you might be advised to look elsewhere for now. That corner of Bokeh is just not currently maintained, really. Perhaps it should be removed entirely.

However, since I don’t know your actual requirements, I should mention another possibility for completeness. If you just need to embed standalone Bokeh content (which can be plots and even widgets with CustomJS callbacks) then all the APIs for standalone embedding will work fine with Django:

In fact you could even use the “standard” Bokeh server app embedding functions server_document and server_session with Django, as long as the Bokeh server was running separately. It’s only the very specific and narrow feature for “direct” Django / Bokeh server integration that is currently in bad shape.

My current project is developing a web-base monitor system of a factory. Some views are like the following figures.

The data of these figures comes from a postgresql database, and the data will be updated dynamically. The objective is updating these figures with newest information automatically or periodically. I think all these figures can be showed with bokeh plots or figures. The only bokeh’s way l knew is callback function. If I want the these figures updated periodically, I have to using bokeh serve. In a web system, users could choose any figure. I don’t know how to use bokeh components to developing my web system.

I can’t say for sure if it is suitable to your case or not, but it is possible to update standalone Bokeh plots using AjaxDataSource or ServerSentDataSource (without a Bokeh server).

bokeh/ at branch-2.4 · bokeh/bokeh · GitHub

bokeh/ at branch-2.4 · bokeh/bokeh · GitHub

  1. I didn’t see anything after run “python”.
  2. Does multiple python files can run simultaneously? If the answer is “yes”, then the output html file can be loaded simultaneously.
  3. If the answer of question #2 is “yes”, Django seems not necessary any more?

@yvechang I guess it seemed Django was a pre-existing requirement. If that is not the case, if you don’t need Django for some external reason, then you could just create a “normal” Bokeh server app (i.e. run with the bokeh serve command) as described here:

That kind of Bokeh server app usage (without Django) is very well known, established, and supported for many years now.

  1. I didn’t see anything after run “python”.

You mean a browser did no open up the page automatically? If not you will have to open up the ajax_source.html output file manually. We just use the built-in standard Python webbrowser module to try to open a browser for you, but if that does not work it’s not really a Bokeh issue, and we can’t do anything about it.

it is blank

Any JS console messages? I seem to recall there can be CORS permission issues in some platforms or instances.

Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.

That looks like the shell console, I mean the browser’s JavaScript console.

Access to XMLHttpRequest at ‘http://localhost:5050/data’ from origin ‘null’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

[bokeh] Failed to fetch JSON from http://localhost:5050/data with code 0

bokeh-2.3.0.min.js:531 POST http://localhost:5050/data net::ERR_FAILED

Right, the toy example in the repo does not set any CORS headers on the /data endpoint, and some browsers apparently don’t like that. Any real API endpoint that you would point AjaxDataSource at would presumably not have this issue. If you’d like to make a PR to update the example to set the Access-Control-Allow-Origin header in the response that would certainly be appreciated.

Do you mean the codes in lines 41 and 42? These codes are already written in the execute python file “”

I see that evidently it does. I am not sure why it is not working on your system, it is working for me on OSX Safari or Chrome.

@yvechang. First, the point of my post was to get a bug fix going for bokeh so it can work with Django 3.2. Until this is done, we are using Django==3.1.8, bokeh==2.3.1, panel==0.11.1, and channels<3.
We are using the NGINX server to handle https:// and steer http:// to https://. We use Hypercorn==0.11.2 to serve Django as follows:
–bind localhost:8001 .asgi:application

So this is the setup, in the Django app we do some more things but I don’t know all the details and we don’t have a simple stripped down example. We did get it working though.

@ejprinz Thanks for your sharing details. Could you try django_embed(1.4) or django_embed(2.4)? I had change the version of Django==3.1.8, bokeh==2.3.1, panel==0.11.1, and channels==2.4. But as I run: runserver

The following message occurred:
LookupError: No installed app with label ‘bokeh.server.django’. Did you mean ‘bokeh_server_django’?