HTML
<el-button class="btns" size='mini' type="success" @click='downloadFun'>下载</el-button>
JS
//data
fileUrl: ''
//methods
downloadFun() {
location.href = site_url + 'file_down/?url=' + this.fileUrl
},
Python
def file_down(request):
url = request.GET.get('url')
if url is None:
return render_json({'result': False, 'data': '请传入文件路径参数url'})
name_li = url.split('$')
file_name = name_li[-1]
f = open(url,'rb')
response =HttpResponse(f)
response['Content-Type']='application/octet-stream'
response['Content-Disposition']="attachment;filename*=utf-8''{}".format(escape_uri_path(file_name))
return response
网友评论