2016-08-09 13 views
0

私はdjangoプロジェクトの設定をしています。私はpivotottable.js(https://github.com/nicolaskruchten/pivottable)を使用して、ピボット可能な新しいページを追加しようとしています。pivotottable.js関数内のコンテキストデータの参照方法

私の問題は、{ pivotottable.js jQuery関数です。私のviews.pyで

:pivottable.htmlで

def sysdev_pivottable(request): 
    context = {} 
    csvString = "" 
    with open("W:\\data.csv", 'rb') as csvfile: 
     reader= csv.reader(csvfile, delimiter=',', quotechar='|') 
     for row in reader: 
      csvString = csvString + ','.join(row) 

    context['data'] = csvString 
    template = loader.get_template('pivottable.html') 
    return HttpResponse(template.render(context, request)) 

...

<h1> Test load: {{ data }}</h1> #this displays data properly 
<script type="text/javascript"> 

$(function() 
{ 
    var input1 = "1,2,3,4" #test data declared within the function() 
    $("#output").pivotUI(input1, {}); #this loads properly 
    var input2 = {{data}} ##this doesn't work, would break the rest of the <script> 
}); 
    </script> 
     <div id="output" style="margin: 10px;"> 
     </div> 

私は$(function(){})の中から適切{{data}}ロードする方法がわかりません。 $(function(){})の外から{{data}}を正しく読み込むことができます。助けてくれてありがとう

+0

= {{データ}} 'のvar INPUT2'へ= "{{データ}}" 'VARのINPUT2を'変更し、エラーが私はそれを試してみました –

+0

@AnnaVrachevaを表示されたかどうかを確認してくださいあまりにも、それは私が見ることができないエラーをスローするように何もロードされていないWebページになります。問題は、$(function())ブロック内のコンテキストデータ(任意の{{key}})を参照すると、ブロック

関連する問題