Django + Bokeh + autoload_server:按图得到一个div

时间:2017-03-27 08:13:04

标签: python django bokeh

使用Bokeh 0.12.4和django 1.10.6,如​​何使用script为个人figure获取autoload_server

myapp/main.py

from bokeh.plotting import Figure
from bokeh.io import curdoc
fig1= Figure(plot_width=500, plot_height=300, name='fig1')
fig2 = Figure(plot_width=500, plot_height=300, name='fig2')
curdoc().add_root(fig1)
curdoc().add_root(fig2)

mysite/views.py中,我想做类似的事情:

from django.shortcuts import render
from bokeh.embed import autoload_server
def index(request):
    script1 = autoload_server(model='fig1', url="http://localhost:5006/myapp")     
    script2 = autoload_server(model='fig2', url="http://localhost:5006/myapp")                        
    return render(request, 'index.html', context={'script1': script1, 'script2': script2})

然后将脚本放在我想要的html模板mysite/templates/index.html中:

<div>
    {{script1 | safe }}
</div>

<div>
    {{script2 | safe }}
</div>

0 个答案:

没有答案