実現ファイル

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

おすすめ

転載: www.cnblogs.com/0916m/p/11481877.html