JavaScript模拟点击点击超链接下载文件

Python:
path=''
file_name=''
with open(os.path.join(path, file_name), 'rb') as file_read:
file = file_read.read()
response = HttpResponse(file)
response["Content-Type"] = "application/octet-stream"
response["Content-Disposition"] = 'attachment; filename={0}'.format(file_name)
response["Access-Control-Expose-Headers"] = "Content-Disposition"
return response
JavaScript:
let download_file_name = res.headers["content-disposition"].split(';')[1].split('filename=')[1];
let url = window.URL.createObjectURL(new Blob([res.data]))
let a = document.createElement('a')
a.style.display = 'none'
a.href = url
a.setAttribute('download', download_file_name)
document.body.appendChild(a)
a.click() //执行下载
window.URL.revokeObjectURL(a.href)
document.body.removeChild(a)