大家好
我想从字典里写一个csv文件。我只是把csv\u数据改成了字典
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="some_file(%s).csv"'
csv_data = {'data' : [('quick', 'brown', 'fox', 'jump'), ('over', 'the', 'lazy', 'dog'), 'total' : 23, 'subtotal': 4}
t = loader.get_template('main/report/contract_position.txt')
c = Context({
'csv_data' : csv_data,
})
response.write(t.render(c))
return response
在我的.txt文件中
"header1", "header2", "header3", "header4", "total", "subtotal"
{% for item in csv_data %}
???? #what should be here. Cuz I can't do something item.0|addslashes. It only takes out the first character of the string
{% endfor %}
我想在里面制作一些类似的东西。你知道吗
header1 header2 header3 header4
quick brown fox jump
over the lazy dog
total subtotal
23 4
任何帮助都将不胜感激。谢谢
使用^{} :
相关问题 更多 >
编程相关推荐