In views.py
from django.shortcuts import render
from django.template.loader import get_template
from django.http import HttpResponse
from bokeh.plotting import figure, output_file, show
from bokeh.embed import components
# Create your views here.
def homepage(request):
template = get_template('index.html')
plot = figure()
plot.line([1,2,3,4,5],[5,4,3,2,1])
script, div = components(plot)
html = template.render(locals())
return HttpResponse(html)
In the templates/index.html
i use the bokeh to generate the following code:
<div class="bk-root">
<div class="plotdiv" id="a3a4c265-dec8-4057-b9ed-d39afda33e2d"></div>
</div>
And when i use the {{div | safe}}
But the result show nothing
how should i do to make the graphic show?
update 'templates/index.html'
{{ div | safe }}
<script type="text/javascript" src="http://cdn.bokeh.org/bokeh/release/bokeh-0.9.0.min.js"></script>
{{ script | safe }}
0.9.0!? That's very old, if you are running a recent/current version of the python library then that mismatch is almost certainly the problem. The BokehJS version from CDN (i,e. the version in the script tag) and the installed python library version need to match.