django - 实现文件下载

django 实现文件下载

1、通过 response = HttpResponse(bytes)

2、设置下载的头信息

response["Content-Disposition"] = "attachment;filename=文件名"
如果要实现预览效果 (图片、文本文件才支持预览)
response["Content-Disposition"] = "inline;filename=文件名"

3、设置下载的头信息

response["Content-Type"] = "文件的类型"

4、设置下载的头信息

response["Content-Length"] = 文件的大小

猜你喜欢

转载自www.cnblogs.com/leomessi10/p/11871711.html