文件下载,后端接口,django,flask
2024-10-11 05:27:24
Django后端接口
def download_excel(request):
"""
get excel file from url param and upload it to html page for downloading
:param request:
:return:
"""
# get file path from a tag url param
excel_file = request.GET.get("EXCEL")
file_byte = open(excel_file, "rb")
response = HttpResponse(file_byte)
# 设置头信息,告诉浏览器这是个文件
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = 'attachment;filename="attendance.xlsx"'
return response
flask后端接口
def download_get_part():
"""
把上面下载post返回的excel文件路径,传入进来,用二进制打开,返给浏览器
:return:
"""
# todo: 待调试,flask的HttpResponse替代品是啥,
excel_file = request.args.get("excel")
# 设置头信息,告诉浏览器这是个文件
file_byte = open(excel_file, "rb")
response = Response(file_byte)
response.headers["Content-Type"] = "application/octet-stream"
response.headers["Content-Disposition"] = "attachment;filename={}".format(
"各节点之间的调用关系.xlsx".encode().decode('latin-1')
)
return response
# 这里是另一种方式提供下载文件接口,只有这一行就够了
# return send_file(excel_file) # website download file successful
最新文章
- [翻译] V8引擎的解析
- kettle定时任务_第三方合作方有订单自动发送邮件通知_20161214
- 基于Metronic的Bootstrap开发框架经验总结(8)--框架功能总体界面介绍
- Python3 学习第八弹: 模块学习一之模块变量
- paip.超实用 360浏览器最近频繁奔溃解决流程.
- 让IIS识别PUT和DELETE请求
- High performance web site
- html 自定义标签的作用
- 201521123054 《Java程序设计》第11周学习总结
- 深入理解计算机系统_3e 第六章家庭作业 CS:APP3e chapter 6 homework
- hash解密小助手-python版
- ActiveMQ笔记:源码分析
- HBase 健康检查工具
- java中的JSON数据转换方法fastjson
- java Encryption&;Decryption
- Object.keys的使用
- 开源中文分词框架分词效果对比smartcn与IKanalyzer
- 委托、Lambda表达式、事件系列05,Action委托与闭包
- 【LOJ】#2055. 「TJOI / HEOI2016」排序
- 2017-2018-2 20179207 《网络攻防技术》第十三周作业 python3实现SM234算法