在 django 模板中渲染 Bokeh 小部件
Rendering Bokeh widgets in django Templates
我是 django 和散景的新手。
我试图渲染一个由几个 select 选项支持的简单散景图,这些选项基本上允许我在 django 网络应用程序中调整我的图内容。
当从 bokeh.embed.components()
获得的 script
和 div
元素作为上下文变量传递给模板时,将呈现这些图。
当我有一个小部件和一个 bokeh.io.vform
对象中的绘图时,同样的方法不起作用。
当我通过指定 bokeh.plotting.output_file()
执行 bokeh.io.show()
时,我得到了正确的输出,但我试图在我的 Web 应用程序中得到这个 运行。
我错过了什么吗?或者是否有任何其他方法符合我的意图?
我只渲染散景小部件的代码如下:
views.py
#django imports
from bokeh.embed import components
from bokeh.plotting import figure
from bokeh.io import vform
from bokeh.models.widgets import Select
def test(request):
s = Select(title="test", value="a", options=['a','b','c'])
script,div = components(s)
return render(request,'test.html',RequestContext(request,{'script':script,'div':div}))
test.html
<html>
<head>
<link href="http://cdn.bokeh.org/bokeh/release/bokeh-0.11.1.min.css" rel="stylesheet" type="text/css">
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.11.1.min.js"></script>
</head>
{% load staticfiles %}
<body>
{{ div | safe }}
{{ script | safe }}
</body>
</html>
我希望在 django 中从 test() 启动 test.html 时呈现 select 表单元素。但不会发生。
BokehJS 最近被拆分成单独的部分,以提供更灵活的使用选项,具体取决于实际使用库的哪些部分。因为在许多情况下加载资源通常是自动处理的,所以无意中忽略了在文档中显着提及这种拆分。但是,了解嵌入很重要。更新文档时出现问题,但您需要知道的是,如果您使用的是小部件,您现在还需要从 CDN 加载额外的脚本:
http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.11.1.min.js
http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.11.1.min.css
我是 django 和散景的新手。 我试图渲染一个由几个 select 选项支持的简单散景图,这些选项基本上允许我在 django 网络应用程序中调整我的图内容。
当从 bokeh.embed.components()
获得的 script
和 div
元素作为上下文变量传递给模板时,将呈现这些图。
当我有一个小部件和一个 bokeh.io.vform
对象中的绘图时,同样的方法不起作用。
当我通过指定 bokeh.plotting.output_file()
执行 bokeh.io.show()
时,我得到了正确的输出,但我试图在我的 Web 应用程序中得到这个 运行。
我错过了什么吗?或者是否有任何其他方法符合我的意图?
我只渲染散景小部件的代码如下:
views.py
#django imports
from bokeh.embed import components
from bokeh.plotting import figure
from bokeh.io import vform
from bokeh.models.widgets import Select
def test(request):
s = Select(title="test", value="a", options=['a','b','c'])
script,div = components(s)
return render(request,'test.html',RequestContext(request,{'script':script,'div':div}))
test.html
<html>
<head>
<link href="http://cdn.bokeh.org/bokeh/release/bokeh-0.11.1.min.css" rel="stylesheet" type="text/css">
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.11.1.min.js"></script>
</head>
{% load staticfiles %}
<body>
{{ div | safe }}
{{ script | safe }}
</body>
</html>
我希望在 django 中从 test() 启动 test.html 时呈现 select 表单元素。但不会发生。
BokehJS 最近被拆分成单独的部分,以提供更灵活的使用选项,具体取决于实际使用库的哪些部分。因为在许多情况下加载资源通常是自动处理的,所以无意中忽略了在文档中显着提及这种拆分。但是,了解嵌入很重要。更新文档时出现问题,但您需要知道的是,如果您使用的是小部件,您现在还需要从 CDN 加载额外的脚本:
http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.11.1.min.js
http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.11.1.min.css