3 回答

TA貢獻1836條經(jīng)驗 獲得超13個贊
方式多種多樣
1, 如果你采用的是ajax請求, 可以返回靜態(tài)文件名字a.xlsx, 把你的報表存放入/static/../ , 前端頁面就直接window.open('/static/../a.xlsx) ,就可以進行下載
2, 返回文件流:
from django.http import StreamingHttpResponse
def big_file_download(request):
def file_iterator(file_name, chunk_size=512):
with open(file_name) as f:
while True:
c = f.read(chunk_size)
if c:
yield c
else:
break
the_file_name = "file_name.txt"
response = StreamingHttpResponse(file_iterator(the_file_name))
return response
- 3 回答
- 0 關(guān)注
- 1995 瀏覽
添加回答
舉報