个人学习记录:
pandas 读取数据库,数据传送前端
from django.http import JsonResponse,HttpResponse,FileResponse
import pandas as pd
import io
import sqlite3
def test(request):
if request.method=='GET':
df=io.BytesIO()
pd.read_sql('select * from test',conn).to_excel(df,index=False)
df.seek(0)
response=FileResponse(df)
response['Content-Type']='application/octet-stream'
response['Content-Disposition']='attachment;filename="{}"'.format(yourfilename)
return response