django - implementation file download

django implementation file download

1、通过 response = HttpResponse(bytes)

2, set to download headers

response["Content-Disposition"] = "attachment;filename=文件名"
If you want to preview the effect (pictures, text files only supports preview)
response["Content-Disposition"] = "inline;filename=文件名"

3, set to download headers

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

4, set to download headers

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

Guess you like

Origin www.cnblogs.com/leomessi10/p/11871711.html