首页 > 其他 > 详细

实现文件的下载

时间:2019-09-07 17:24:01      阅读:68      评论:0      收藏:0      [点我收藏+]
report = CustomHistoryReport.objects.filter(id=reportid)
    if report:
        abs_path = REPORT_PATH + report[0].name + '.xlsx'
        if not os.path.isfile(abs_path):  # 判断下载文件是否存在
            return Response(status=404)
        else:
            with open(abs_path, 'rb') as report:
                file_content = report.read()
            res = file_content
            response = HttpResponse()
                       #声明流数据的类型
            response['Content-Type'] = 'application/octet-stream'
                        #将流数据写入到相应对象中
            response.write(res)
            return response

实现文件的下载

原文:https://www.cnblogs.com/0916m/p/11481877.html

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