django 中 python返回csv文件

    data = model.objects.order_by('-time')
    response = HttpResponse(mimetype="text/csv")
    response['Content-Disposition'] = 'attachment; filename=yourname.csv'
    writer = csv.writer(response)
    writer.writerow(['title1','title2'])
    for item in data:
        writer.writerow([item.platform,item.app_version])
    return response



你可能感兴趣的:(django 中 python返回csv文件)