0

全てにおいて良い日、

辞書からcsvファイルを書きたいと思います。そして、ここのすべてに従いましたhttps://docs.djangoproject.com/en/dev/howto/outputting-csv/ csv_data を辞書に変更しました

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

どんな助けでも大歓迎です。ありがとう

4

1 に答える 1