<script type="text/javascript">
/* csv_list: 从 django 索引函数 (views.py) 得到的列表列表 eg:[['abc','1'],['xyz','0']] */
var data = {{csv_list}};
function genrate_csv() {
var csv = 'Tweet, Polarity\n';
data.forEach(function(row) {
csv += row.join(',');
csv += "\n";
});
console.log(csv);
var new_elm = document.createElement('a');
new_elm.href = 'data:text/csv;charset=utf-8,' + encodeURI(csv);
new_elm.target = '_blank';
new_elm.download = 'data.csv';
new_elm.click();
}
</script>
显示报价的 html 代码时出错 显示报价的 html 代码时出错
django code: (views.py)
def index(request):
if request.method=="POST" and request.POST.get('query') != "":
tweet_list =
script.tweets(request.POST.get('query'),request.POST.get('numtweets'))
pos,neg,net,csv_list = script.analysis(tweet_list)
context = {
'tweet_list' : tweet_list,
'csv_list' : csv_list, #passed the list of list
't': len(tweet_list)
}
return render(request,"index.html",context)
守着一只汪
相关分类