聞きたいこと
Djangoで実装されているWebアプリのあるDBのテーブルデータをすべてCSV形式で出力したいと思っているのですが、下のエラーが表示されてしまっていてできません。
ascii' codec can't encode characters in position 4-11: ordinal not in range(128)
ソースコード
# -*- coding: utf-8 -*- : import unicodecsv as csv : def download(request): # レスポンスの設定 response = HttpResponse(content_type='text/csv') filename = 'report.csv' response['Content-Disposition'] = 'attachment; filename={}'.format(filename) writer = csv.writer(response, encoding='utf-8') # ヘッダーの設定 header = ['id', 'title', 'content'] writer.writerow(header) notes = Note.filter_by_team(team) for data in notes: writer.writerow([data.id, data.title, data.content]) return response
やってみたこと
あなたの回答
tips
プレビュー