首页 > 其他 > 详细

django 下载文件

时间:2019-04-13 15:27:20      阅读:105      评论:0      收藏:0      [点我收藏+]
from django.http import StreamingHttpResponse 

def big_file_download(request):   

 # do something...    

    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

 

django 下载文件

原文:https://www.cnblogs.com/zhengze/p/10701231.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!