(2)方法二、在python后台对下载内容进项处理,返回内容直接弹出下载框。
#后台处理函数
def downloadFile(req):
filename=basePath+req.GET['url']
def file_iterator(file_name, chunk_size=512):
with open(file_name) as f:
while True:
c = f.read(chunk_size)
if c:
yield c
else:
break
response = StreamingHttpResponse(file_iterator(filename))
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="{0}"'.format(filename)
return response
(3)前台使用函数方法
①、a标签调用函数传入路径
②、button标签调用jq方法调用后台函数
#下载按钮点击事件
$("body").on("click",".download",function(){3 location.href="/downloadFile/?url="+路径;
});
查看更多关于Python+django实现文件下载的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did89417