【发布时间】:2017-12-06 14:08:39
【问题描述】:
我遇到了一个问题,我需要在 API 的响应中发送 excel 文件,但数据量很大。 数据来自 Django 模型查询,然后我对其进行迭代并保存到如下变量:
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 模型查询的响应时,JSON 不会保存在它创建的任何文件中
【问题讨论】:
标签: json django excel python-3.x api