gpt4 book ai didi

javascript - Django:Bokeh.safely 不是函数

转载 作者:太空狗 更新时间:2023-10-30 02:08:24 24 4
gpt4 key购买 nike

我试图将 Bokeh 图嵌入到我的 Django 应用程序中。我按照 Bokeh website 上给出的说明进行操作和 another question .

我在我的浏览器控制台上收到以下错误并且没有得到任何绘图输出:

Uncaught TypeError: Bokeh.safely is not a function
at HTMLDocument.fn (localhost/:15)

我不是 JS 专家,但 Bokeh.safely 存在于 Bokeh 生成的脚本中。我附上了最后生成的脚本:

我的 views.py 文件:

from django.shortcuts import render
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import components

def showGraph(request):
arr = [1,4,9,16,25,36]
y = [1,2,3,4,5,6]
plot = figure()
plot.line(arr, y)

script, div = components(plot, CDN)

return render(request, "data_collection/simple_chart.html", {"script": script, "div": div})

simplechart.html 文件:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Bokeh example</title>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.0.min.css">
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.0.min.css">
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.0.min.js"></script>
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-0.12.0.min.js"></script>

{{ script | safe }}
</head>
<body>

{{ div | safe }}


</body>
</html>

Bokeh 生成的脚本:

(function(){
var fn = function(){
Bokeh.safely(function(){
var docs_json = {....json.....};
var render_items = [
{"docid": "27fe9292-3142-4617-b273-f9d932e47df3", "elementid": "7b2ef36e-a7d2-4a6b-88e6-186edecde6ca",
"modelid": "741db3b0-26ce-45c1-86b4-d95394c7331f"}];

Bokeh.embed.embed_items(docs_json, render_items);
});
};
if (document.readyState != "loading") fn();
else document.addEventListener("DOMContentLoaded", fn);
})();

最佳答案

您正在 simplechart.html 模板中从 CDN 加载 BokehJS 的 0.12.0 版本,但几乎可以肯定的是,您使用的是较新版本的 BokehJS Python Bokeh 库比那个。 BokehJS 和 (Python) Bokeh 库的版本必须匹配。

关于javascript - Django:Bokeh.safely 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43612360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com