问题描述
我正在使用Django2和REST框架。我想添加一个临时文件tempfile.SpooledTemporaryFile()
进行响应。我的代码:
class MyViewSet(viewsets.ViewSet):
@action(
detail=False,methods=["post"]
)
def return_file(self,request,**kwargs):
excel_file = request.data.get("in_file")
df = pd.read_excel(excel_file)
temp = tempfile.SpooledTemporaryFile()
df.to_excel(excel_writer=temp)
response = Response(temp,content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-disposition'] = 'attachment; filename="returned_file"'
return response
我正在使用邮递员发布到该端点,但是在响应中什么都没有看到。我如何注意到该文件已返回?我的代码应该返回文件吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)