2016-12-29 15 views
0

看到在views.py背景虛化和Django不能在網站

from django.shortcuts import render 
from django.template.loader import get_template 
from django.http import HttpResponse 
from bokeh.plotting import figure, output_file, show 
from bokeh.embed import components 
# Create your views here. 
def homepage(request): 
    template = get_template('index.html') 
    plot = figure() 
    plot.line([1,2,3,4,5],[5,4,3,2,1]) 
    script, div = components(plot) 
    html = template.render(locals()) 
    return HttpResponse(html) 

templates/index.html

我使用背景虛化生成以下代碼:

<div class="bk-root"> 
    <div class="plotdiv" id="a3a4c265-dec8-4057-b9ed-d39afda33e2d"></div> 
</div> 

當我使用{{div | safe}}

但結果顯示沒有

我應該怎麼做圖形顯示?

更新「模板/ index.html的」

{{ div | safe }} 
<script type="text/javascript" src="http://cdn.pydata.org/bokeh/release/bokeh-0.9.0.min.js"></script> 
{{ script | safe }} 
+0

你模板化時返回過腳本?您必須將腳本和div包括在您的模板中。 – bigreddot

+0

這個問題可能會有所幫助:http://stackoverflow.com/questions/29508958/how-to-embed-bokeh-graphs-into-django-templates-without-using-the-bokeh-server – AMG

+0

@bigreddot是的,我也回來了。我更新 –

回答

0

從CDN的BokehJS版(script標籤)必須對應於Python庫版本