我正在从视图文件发送字典到django模板。在Django模板中我使用字典值创建一个表。我的要求是在表下面有一个“下载”按钮,这样当我点击按钮表时应该在excel表中下载?怎么做到这一点?
模板:
{% for set_name,set_value in pass_test_results.items %}
<table id="final_result">
<tr id="top-grad">
<td colspan='4'> Ip-Address : {{set_value.ip_address}}</td>
<td> ScanTime : {{set_value.scan_time}}</td>
</tr>
<tr id="table-second-top-grad">
<th>Operating system</th>
<th>Software</th>
<th>Bulletin number</th>
<th>MainKb</th>
<th>SubKB</th>
</tr>
{% if set_value.missing_updates %}
{% for category, cat_value in set_value.missing_updates.items %}
{% if cat_value %}
<tr>
<td colspan='5' style='background-color:#81A594;'> category : {{ category }} </td>
</tr>
{% for software, soft_value in cat_value.items %}
{% if soft_value %}
{% for main_kb, kb_info in soft_value.items%}
{% if kb_info %}
<tr>
{% if category == 'OS' %}
<td>{{ software }}</td>
{% else %}
<td>{{ kb_info.os }}</td>
{% endif %}
<td>{{ software }}</td>
<td>{{ kb_info.b_no }}</td>
<td>{{ main_kb }}</td>
<td>{{ kb_info.sub_kb_list|unordered_list }}</td>
</tr>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
<tr>
<td colspan='5' style='background-color:#D74B4B;'>Error Messsage : </td>
</tr>
{% endif %}
</table>
</br>
<input class="download_button" value="Download" type="submit" name="table_download"/>
<input class="save_to_repo_button" value="Save In Database" type="submit" name="table_save_to_repo"/>
</br></br>
{% endfor %}
Views.py:
final_dict = {
'set_1':{
'missing_updates' :{
'office': {},
'OS': {u'Windows Vista Service Pack 0': {'123456': {'b_no': 'MS12-098', 'sub_kb_list': ['123456', '789568']}}},
'Servers': {},
'applications': {u'Windows media player 11.0': {'555555': {'os': '', 'b_no': 'MS13-087', 'sub_kb_list': ['222222', '1111111']}}},
'IE': {u'Internet Explorer 7': {'78787878': {'os': 'Windows Vista Service Pack 0', 'b_no': 'MS13-045', 'sub_kb_list': ['000000', '11111111111']}, '67676767': {'os': '', 'b_no': 'MS13-100', 'sub_kb_list': ['343434', '11212121']}}},
'Tools': {u'DotNet 2.0 SP2': {'999999': {'os': '', 'b_no': 'MS12-086', 'sub_kb_list': ['8888888', '777777']}, '123456': {'os': 'Windows Vista Service Pack 0', 'b_no': 'MS12-086', 'sub_kb_list': ['456789']}}, u'DotNet 3.0 SP2': {'975467': {'os': '', 'b_no': 'MS13-076', 'sub_kb_list': ['975467', '12467']}}}
},
'ip_address': '192.168.65.120',
'scan_time': '2013-12-10 07:46:36+00:00',
}
}
return render(request, 'final_output.html', {'pass_test_results': final_dict})