将JSON写入Excel并发送回应API

我陷入了一个问题,我需要在API的响应中发送Excel文件,但数据量是巨大的。 数据来自Django模型查询,然后我迭代它并保存到一个variables,如:

data=[ { 'title': 'xxxx', 'website': 'xxxx', 'state': 'CA ', 'second_followup': None, 'fourth_followup': datetime.datetime(2017-5-3-0-0-tzinfo=<UTC>), 'first_followup': None, 'first_reponse': '', 'type': 'a', 'email_status': 'xxx', 'team_size': 0, 'second_reponse': '', 'bed_count': 0, 'created_at': datetime.datetime(2016-8-30-0-0-tzinfo=<UTC>), 'aum': 0, 'bounce': None, 'lead_status': 'xxxx', 'founded_year': '0000', 'third_followup': None, 'last_name': 'xxxx', 'address': 'xxxx', 'email': 'xxxx', 'created_by': 'xxxx', 'specialties': 'xx', 'response_date': None, 'first_name': 'xxxx ', 'zip': 'xxxx', 'company_source': 'xxxx', 'revenue': 5.0, 'company_name': 'xxxx', 'fax_number': '0', 'inital_contact': datetime.datetime(2017-5-3-0-0-tzinfo=<UTC>), 'contact_number': '0', 'domain1': 'xxx', 'city': '0', 'country': 'USA', 'industry': 'xxx', 'department': 'a', 'domain2': 'xxx', 'contact_source': 'xxx', 'fifth_followup': None }, { 'title': 'xxxx', 'website': 'xxxx', 'state': 'CA ', 'second_followup': None, 'fourth_followup': datetime.datetime(2017-5-3-0-0-tzinfo=<UTC>), 'first_followup': None, 'first_reponse': '', 'type': 'a', 'email_status': 'xxx', 'team_size': 0, 'second_reponse': '', 'bed_count': 0, 'created_at': datetime.datetime(2016-8-30-0-0-tzinfo=<UTC>), 'aum': 0, 'bounce': None, 'lead_status': 'xxxx', 'founded_year': '0000', 'third_followup': None, 'last_name': 'xxxx', 'address': 'xxxx', 'email': 'xxxx', 'created_by': 'xxxx', 'specialties': 'xx', 'response_date': None, 'first_name': 'xxxx ', 'zip': 'xxxx', 'company_source': 'xxxx', 'revenue': 5.0, 'company_name': 'xxxx', 'fax_number': '0', 'inital_contact': datetime.datetime(2017-5-3-0-0-tzinfo=<UTC>), 'contact_number': '0', 'domain1': 'xxx', 'city': '0', 'country': 'USA', 'industry': 'xxx', 'department': 'a', 'domain2': 'xxx', 'contact_source': 'xxx', 'fifth_followup': None },... and so on ] 

在上面我有超过10000个数据,所以我怎样才能把这些数据写入excel文件并把它发送给API响应,这样用户就可以下载文件了。 文件不会保存在服务器上这是另一个要求

在迭代Django Model Query的响应时,JSON不保存在创build的任何文件中

发送variables到客户端,创build一个临时的JSON文件,并使用JavaScript和Json2Flat将其转换为.csv

该库将JSON文档转换为CSV。 它使用谷歌Gson和JsonPath进行转换。 您可以稍后删除JSON文件,或者将其作为客户端的替代方法发送。