目录
views中主要代码:
from django.http import StreamingHttpResponse def download(request): file=open(‘crm/models.py‘,‘rb‘) response =StreamingHttpResponse(file) response[‘Content-Type‘]=‘application/octet-stream‘ response[‘Content-Disposition‘]=‘attachment;filename="models.py"‘ return response
views中主要代码:
from django.http import FileResponse def download(request): file=open(‘crm/models.py‘,‘rb‘) response =FileResponse(file) response[‘Content-Type‘]=‘application/octet-stream‘ response[‘Content-Disposition‘]=‘attachment;filename="models.py"‘ return response
see also:详解django三种文件下载方式 | Django实现下载文件
原文:https://www.cnblogs.com/l-hf/p/12120758.html