FileResponse
代码如下
down_file = open(file_path, 'rb')
f_name = file_name.split('/')[-1]
# f_name 计算机作业.xls
response = FileResponse(down_file, filename=f_name, as_attachment=True)
response['Content-Type'] = 'application/octet-stream'
return response
FileResponse里的参数
第一个是下载的文件。
第二个是下载后的显示的文件名,filename=‘aaa.txt’表示要下载的文件为aaa.txt,
第三个我也不太清楚
注意扩展名