将散景图嵌入到模板中(django)
Embeding bokeh plot into a template (django)
我正在尝试将散景图嵌入模板 (home.html),但执行代码后没有显示任何内容。
这是代码。
views.py(所有包都是导入的)
def home(请求):
s = [1,4,6,8]
h = [1,5,9,8]
p = figure(plot_width=600, plot_height=600)
p.vbar(x=s, width=0.5, bottom=0,
top=h, color="black")
script, div = components(p, CDN)
return render(request, 'home.html', {'div': div, 'script': script})
home.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Experiment with Bokeh</title>
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.js"></script>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.css">
</head>
<body>
<h1>hello</h1>
{{ div|safe }}
{{ script|safe }}
</body>
</html>
最后什么都不显示,也没有错误信息,但是页面完全空白
求助!!
您正在从 CDN 加载 旧版本 BokehJS:
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.js"></script>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.css">
0.8.1 版本现在 几年 了。相比之下,您使用的 vbar
字形方法是最近才添加的。您需要确保您在模板中加载的 BokehJS 资源的版本实际上与您正在使用的 Bokeh 库的版本相匹配。
我正在尝试将散景图嵌入模板 (home.html),但执行代码后没有显示任何内容。 这是代码。
views.py(所有包都是导入的)
def home(请求):
s = [1,4,6,8]
h = [1,5,9,8]
p = figure(plot_width=600, plot_height=600)
p.vbar(x=s, width=0.5, bottom=0,
top=h, color="black")
script, div = components(p, CDN)
return render(request, 'home.html', {'div': div, 'script': script})
home.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Experiment with Bokeh</title>
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.js"></script>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.css">
</head>
<body>
<h1>hello</h1>
{{ div|safe }}
{{ script|safe }}
</body>
</html>
最后什么都不显示,也没有错误信息,但是页面完全空白
求助!!
您正在从 CDN 加载 旧版本 BokehJS:
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.js"></script>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.8.1.min.css">
0.8.1 版本现在 几年 了。相比之下,您使用的 vbar
字形方法是最近才添加的。您需要确保您在模板中加载的 BokehJS 资源的版本实际上与您正在使用的 Bokeh 库的版本相匹配。