用django传文件到前端,我已经设置了强制下载,但是前端没有下载的操作
```python
class DownLoadFile(View):
def get(self,request):
file_path = r"D\PycharmProjects\ssz\练习\test1.py"
file_name = "test1.py"
response = StreamingHttpResponse(read_file(file_path))
response["Content-Type"] = "application/octet-stream"
response["Content-Disposition"] = 'attachment; filename={0}'.format(file_name)
response["Access-Control-Expose-Headers"] = "Content-Disposition" # 为了使前端获取到Content-Disposition属性
return response
```
你前端的代码怎样写的?如果是前后端分离,你要看看怎样处理
通过Content-Disposition attachment响应头下载文件需要浏览器直接访问网址,不能通过ajax来请求,这样无法弹出保存对话框
ajax的话需要用到blob生成url+链接来下载,参考:
https://ask.csdn.net/questions/7579435?answer=53605821
有帮助或启发麻烦点下【采纳该答案】,谢谢~~