当前位置:   article > 正文

django使用pandas下载excel文件_django pandas 数据导出到excel

django pandas 数据导出到excel

个人学习记录:

pandas 读取数据库,数据传送前端

  1. from django.http import JsonResponse,HttpResponse,FileResponse
  2. import pandas as pd
  3. import io
  4. import sqlite3
  5. def test(request):
  6. if request.method=='GET':
  7. df=io.BytesIO()
  8. pd.read_sql('select * from test',conn).to_excel(df,index=False)
  9. df.seek(0)
  10. response=FileResponse(df)
  11. response['Content-Type']='application/octet-stream'
  12. response['Content-Disposition']='attachment;filename="{}"'.format(yourfilename)
  13. return response

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/897281
推荐阅读
相关标签
  

闽ICP备14008679号