Python Django网站中的Bokeh渲染问题

Python Django网站中的Bokeh渲染问题,python,django,bokeh,Python,Django,Bokeh,在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

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)
templates/index.html

我使用bokeh生成以下代码:

<div class="bk-root"> 
    <div class="plotdiv" id="a3a4c265-dec8-4057-b9ed-d39afda33e2d"></div> 
</div> 

CDN中的BokehJS版本(在script标记中)必须与python库版本相对应

是否也对返回的脚本进行了模板化?您必须在模板中同时包含脚本和div。这个问题可能会有所帮助:@bigreddot是的,我也返回了。我在上面更新了一下,您是否真的在使用Bokeh版本
0.9.0
!?这是非常古老的,如果您运行的是最新/最新版本的python库,那么这种不匹配几乎肯定是问题所在。CDN中的BokehJS版本(即脚本标记中的版本)和安装的python库版本需要匹配.thx!!它确实有用!!因为我在网上复制了教程,所以忽略了版本是否匹配xdd
{{ div | safe }}
<script type="text/javascript" src="http://cdn.bokeh.org/bokeh/release/bokeh-0.9.0.min.js"></script>
{{ script | safe }}