小编Ara*_*ash的帖子

Python-Django utf-8 csv.writer

即时通讯使用python csv库将我的模型导出到Django中的csv文件中。代码是这样的:

import csv
from django.http import HttpResponse

def some_view(request):
    # Create the HttpResponse object with the appropriate CSV header.
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename="somefilename.csv"'

    writer = csv.writer(response)
    writer.writerow(['First row', 'Foo', 'Bar', 'Baz'])
    writer.writerow(['Second row', 'A', 'B', 'C', '"Testing"', "Here's a quote"])

    return response
Run Code Online (Sandbox Code Playgroud)

我的问题: 在我的数据库中,我有一些波斯字符,只能使用utf-8编码格式,因此当我在excel中打开生成的csv文件时,波斯字符无法正确显示。

python csv django utf-8

0
推荐指数
2
解决办法
1203
查看次数

标签 统计

csv ×1

django ×1

python ×1

utf-8 ×1