python下载优秀作业的例子,前端老是无法正常下载

    file_path = os.path.join(settings.COURSE_RELATED, str(courseid), 'courseware', '课件.zip')
        if os.path.exists(file_path):
            with open(file_path, "rb") as file_zip:
                data = file_zip.read()
            response = HttpResponse(data, content_type='application/zip;charset=utf-8')
            response['Content-Disposition'] = 'attachment; filename=kejian.zip'
            return response
            # response = StreamingHttpResponse(file_iterator(file_path))
            # response['Content-Type'] = 'application/octet-stream'
            # response['Content-Disposition'] = 'attachment;filename="{0}"'.format('kejian')
            # return response
        else:
            return Response({'error_no': -1, 'userinfo': True, 'error_msg': "该课程没有课件哦"})
    else:
        return Response({'error_no': -1, 'error_msg': "参数错误"})
except:
    return Response({'error_no': -1, 'error_msg': "下载出错,稍后再试"})


清心流易
浏览 1987回答 1
1回答

pardon110

请先行阅读提问的艺术
打开App,查看更多内容
随时随地看视频慕课网APP