Gha*_*kfa 31 django django-templates python-2.7 bokeh
我想通过django框架在我的Web应用程序中显示散景库提供的图形,但我不想使用散景服务器可执行文件,因为它不是好方法.那有可能吗?如果是的话怎么做?
iMi*_*twe 52
使用Fabio Pliger建议的Embedding Bokeh Plots文档示例,可以在Django中执行此操作:
在views.py文件中,我们把:
from django.shortcuts import render
from bokeh.plotting import figure
from bokeh.resources import CDN
from bokeh.embed import components
def simple_chart(request):
plot = figure()
plot.circle([1,2], [3,4])
script, div = components(plot, CDN)
return render(request, "simple_chart.html", {"the_script": script, "the_div": div})
Run Code Online (Sandbox Code Playgroud)
在urls.py我们可以放的文件中:
from myapp.views import simple_chart
...
...
...
url(r'^simple_chart/$', simple_chart, name="simple_chart"),
...
...
Run Code Online (Sandbox Code Playgroud)
在simple_chart.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>
{{ the_div|safe }}
{{ the_script|safe }}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
它有效.
| 归档时间: |
|
| 查看次数: |
13778 次 |
| 最近记录: |