彩世界平台-彩世界时时app-彩世界开奖app苹果下载

热门关键词: 彩世界平台,彩世界时时app,彩世界开奖app苹果下载

您的位置:彩世界平台 > 彩世界平台 > python Django 文件下载示例

python Django 文件下载示例

发布时间:2019-09-01 00:07编辑:彩世界平台浏览(113)

    python Django 文件下载示例,

     1 from django.http import StreamingHttpResponse#文件流
     2 
     3 
     4 def big_file_download(request):
     5     # do something...
     6 
     7     def file_iterator(file_name, chunk_size=512):
     8         with open(file_name,'rb') as f:
     9             while True:
    10                 c = f.read(chunk_size)
    11                 if c:
    12                     yield c
    13                 else:
    14                     break
    15 
    16     the_file_name = "big_file.pdf"
    17     response = StreamingHttpResponse(file_iterator(the_file_name))
    18     response['Content-Type'] = 'application/octet-stream'
    19     response['Content-Disposition'] = 'attachment;filename="{0}"'.format(the_file_name)
    20 
    21     return response
    22 
    23 链接:http://www.jianshu.com/p/2ce715671340
    25 來源:简书  作者:Gevin
    

     

     
    

    Django 文件下载示例, 1 from django.http import StreamingHttpResponse # 文件流 2 3 4 def big_file_download(request): 5 # do something... 6 7 def file_iterator(file...

     1 from django.http import StreamingHttpResponse#文件流
     2 
     3 
     4 def big_file_download(request):
     5     # do something...
     6 
     7     def file_iterator(file_name, chunk_size=512):
     8         with open(file_name,'rb') as f:
     9             while True:
    10                 c = f.read(chunk_size)
    11                 if c:
    12                     yield c
    13                 else:
    14                     break
    15 
    16     the_file_name = "big_file.pdf"
    17     response = StreamingHttpResponse(file_iterator(the_file_name))
    18     response['Content-Type'] = 'application/octet-stream'
    19     response['Content-Disposition'] = 'attachment;filename="{0}"'.format(the_file_name)
    20 
    21     return response
    22 
    23 链接:http://www.jianshu.com/p/2ce715671340
    25 來源:简书  作者:Gevin
    

     

    本文由彩世界平台发布于彩世界平台,转载请注明出处:python Django 文件下载示例

    关键词:

上一篇:装饰器,

下一篇:没有了