【问题标题】:Integration Django and Bokeh - does not display plot集成 Django 和 Bokeh - 不显示绘图
【发布时间】:2020-03-04 13:57:29
【问题描述】:

我正在尝试使用this article的方法集成Django和Bokeh

不幸的是,写完绘图函数后它什么也没有显示。

我的意见.py

def homepage(request):
    x = [1,2,3,4,5]
    y = [1,2,3,4,5]

    plot = figure(title = 'Line Graph', x_axis_label='X-Ax',y_axis_label='Y-Ax',plot_width = 400,plot_height = 400)

    plot.line(x,y,line_width = 2)
    script,div = components(plot)
    return render(request,'repositorys.html',{'script': script,'div': div})

urls.py

urlpatterns = [
    url(r'^$', views.home, name='home'),
    url(r'^repositorys/',views.homepage,name='repositorys'),
    url(r'^repositorys/(?P<pk>\d+)/$', views.repositorys_board, name='repositorys_board'),
    url('admin/', admin.site.urls),

]

和 repository.html

<html>
    <head>
        <link href=”http://cdn.bokeh.org/bokeh/release/bokeh-1.4.0.min.css" rel=”stylesheet” type=”text/css”>
        <link href=”http://cdn.bokeh.org/bokeh/release/bokeh-widgets-1.4.0.min.css" rel=”stylesheet” type=”text/css”>
        <script src=”http://cdn.bokeh.org/bokeh/release/bokeh-1.4.0.min.js"></script>
        <script src=”http://cdn.bokeh.org/bokeh/release/bokeh-widgets-1.4.0.min.js"></script>
    {{ script | safe }}
    </head>

    <body>
    {{ div | safe }}
    </body>
</html>

我的散景版本是 1.4.0

不幸的是,在我的本地主机上什么都没有显示。

【问题讨论】:

  • 您是否检查了浏览器的控制台?散景通常通过浏览器中的 javascript 显示其错误。例如,可以通过 Chrome 中的 ctrl-shift-i 访问控制台。您可能需要重新加载页面。

标签: django bokeh


【解决方案1】:

您添加到 head 的链接包含无效字符 而不是 "

用这些替换它:

<link href= "http://cdn.bokeh.org/bokeh/release/bokeh-1.4.0.min.css" rel="stylesheet" type="text/css">
<link href="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-1.4.0.min.css" rel="stylesheet" type="text/css">
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-1.4.0.min.js"></script>
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-widgets-1.4.0.min.js"></script>

只需进行上述更改,我就可以得到下图。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-10
    相关资源
    最近更新 更多