我在views.py中有以下代码,它将两个列表的压缩字典返回给模板ex.html:
list1=["['a',1,2,3]","['b',4,5,6]","['c',7,8,9]"]
list2=["[12-09-13,pass]","[8-05-12,fail]"]
retrun render_to_response(ex.html,dict(t=zip(list1,list2)))
但它没有工作.zip混合了lists.is有任何解决方案,在模板中单独遍历两个列表。
在模板中我使用t inside for循环
{% for li in t %}
{{li}}
{% endfor %}
java脚本代码.....生成图表:
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart','table']});
function drawVisualization() {
// Some raw data (not necessarily accurate)
var data = google.visualization.arrayToDataTable([
['Job-Names', 'Total', 'Pass', 'Fail'],
{{glist|safe}}
]);
var options = {
title : 'Project Details',
vAxis: {title: "Number of BULDS" ,ticks : [2,4,6,8,10] },
hAxis: {title: "Job-Names" , textPosition : "out" , slantedText : "false" , textStyle : {fontSize : 9}},
is3D: true,
colors : ["#194D86","#33FF66", "#FF3333"],
pointSize: 4
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: false});
}
我正在使用上面两个列表的数据生成图表...我以字符串格式发送此数据...当我在表单dict中返回单个列表时(t =(',')。join( list1))它会生成一个图表..但如果我发送两个列表......什么都没发生..或者可能是我不知道它的解决方案
答案 0 :(得分:1)
要在模板中单独遍历两个列表,
extra_context = {}
extra_context['list1'] = ["['a',1,2,3]","['b',4,5,6]","['c',7,8,9]"]
extra_context['list2'] = ["[12-09-13,pass]","[8-05-12,fail]"]
return render_to_response(ex.html,extra_context)
在你的模板中:
{% for li in list1 %}
{{li}}
{% endfor %}
{% for li in list2 %}
{{li}}
{% endfor %}
答案 1 :(得分:0)
您可以使用dot operator:
访问不同的列表{% for li in t.0 %} // t.0 would be list1
{{li}}
{% endfor %}
{% for li in t.1 %} // t.1 would be list2
{{li}}
{% endfor %}