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

最新文章

  1. [翻译] V8引擎的解析
  2. kettle定时任务_第三方合作方有订单自动发送邮件通知_20161214
  3. 基于Metronic的Bootstrap开发框架经验总结(8)--框架功能总体界面介绍
  4. Python3 学习第八弹: 模块学习一之模块变量
  5. paip.超实用 360浏览器最近频繁奔溃解决流程.
  6. 让IIS识别PUT和DELETE请求
  7. High performance web site
  8. html 自定义标签的作用
  9. 201521123054 《Java程序设计》第11周学习总结
  10. 深入理解计算机系统_3e 第六章家庭作业 CS:APP3e chapter 6 homework
  11. hash解密小助手-python版
  12. ActiveMQ笔记:源码分析
  13. HBase 健康检查工具
  14. java中的JSON数据转换方法fastjson
  15. java Encryption&Decryption
  16. Object.keys的使用
  17. 开源中文分词框架分词效果对比smartcn与IKanalyzer
  18. 委托、Lambda表达式、事件系列05,Action委托与闭包
  19. 【LOJ】#2055. 「TJOI / HEOI2016」排序
  20. 2017-2018-2 20179207 《网络攻防技术》第十三周作业 python3实现SM234算法

热门文章

  1. 踩坑实录---Angular防抖——点击事件
  2. MRS_Debug仿真相关问题汇总
  3. 腾讯出品小程序自动化测试框架【Minium】系列(五)API详解(中)
  4. SQLSERVER 阻塞之 PFS 页到底是什么?
  5. 新版Bing 搜索后台的.NET 技术栈
  6. jwt的一些封装
  7. 【一句话】Redis的3中缓存策略
  8. 接水问题(NOIP 2010 PJT2)
  9. *已解决 java写的简单验证码Servlet实践
  10. Android  JetPack~ LiveData (一)   介绍与使用