其他分享
首页 > 其他分享> > Django - 视图层 - 生成CSV文件

Django - 视图层 - 生成CSV文件

作者:互联网

目录

使用python的csv库

import csv
from django.http import HttpResponse

def some_view(request):
	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

标签:csv,writerow,text,writer,视图,Django,CSV,response
来源: https://blog.csdn.net/qq_33962481/article/details/112138955