1

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 }}
5
  • Are you templating the script that is returned too? You have to include both the script, and the div, in your template. Commented Dec 29, 2016 at 19:52
  • this question might help: stackoverflow.com/questions/29508958/… Commented Dec 30, 2016 at 2:56
  • @bigreddot yes i returned too. i update above Commented Dec 30, 2016 at 7:10
  • Are you actually using Bokeh version 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. Commented Dec 30, 2016 at 16:59
  • thx!!it does work!!because i i copy the tutorial in the net so i ignored if the version be matchedXDD Commented Dec 30, 2016 at 17:29

1 Answer 1

1

The BokehJS version from CDN (in the script tag) must be corresponding to the python library version

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.