从服务器服务下载日志文件(大文本文件)的最佳方式是什么

2024-04-19 00:37:19 发布

您现在位置:Python中文网/ 问答频道 /正文

在“我的生产”文件夹中,有用于存储日志文件的文件夹。我想让html页面使用Django(python)视图从服务器下载“日志文件”(大的.txt文件,大约1.5GB/文件)到客户端计算机。最好的解决方案是什么(下载文件中没有丢失数据,性能良好)

现在我使用这段代码,但下载文件的大小小于服务器中的原始文件:C

with open(file_path, 'rb') as fh:
    response = HttpResponse(fh.read(), content_type="application/force-download")
    response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
    return response

Tags: 文件pathdjango服务器txt文件夹视图客户端