从数据库可以获取多个链接下载文件前端是vue,现在这样写下载一个return就结束了,后面都来不及下载

从数据库可以获取多个链接下载文件前端是vue,现在这样写下载一个return就结束了,后面都来不及下载

def post(self, request):
    '''下载文件'''
    # 获取请求体中原始的JSON数据
    json_str = request.body
    # 使用json模块将原始的JSON数据转字典
    json_dict = json.loads(json_str)
    masterorder_id = json_dict.get('masterorder_id')
    try:
        obj_master = MasterOrder.objects.get(id=masterorder_id)
        if eval(obj_master.filepath):
            for path in eval(obj_master.filepath):
                filename = os.path.basename(path)
                file = open(path, 'rb')
                response = FileResponse(file)
                response['Content-Type'] = 'application/octet-stream'
                response['Access-Control-Expose-Headers'] = "Content-Disposition, Content-Type"

                response['Content-Disposition'] = 'attachment;filename={}'.format(filename)

                return response
        else:
            return JsonResponse(
                {'code': 1, 'error': "File does not exist"})
    except Exception as e:
        return JsonResponse(
            {'code': 1, 'error': "Failed to submit text, the specific reason:" + str(e)})

定义一个列表,把下载的内容放到列表列,最后返回列表

无法做到,请用代码将目录打个临时压缩包,然后将将压缩包流返回给前端

可以贴出代码吗?