Python Django,将文件附件作为HttpResponse返回,我可以获取文件大小吗?

Python Django,将文件附件作为HttpResponse返回,我可以获取文件大小吗?,python,django,download,filesize,Python,Django,Download,Filesize,我正在从weboage返回一个Excel.XLS文件,如: xls_response = HttpResponse(mimetype='application/vnd.ms-excel') xls_response['Content-Disposition'] = 'attachment; filename=funfile.xls' . . <code to generate the file - already accomplished> . . return xls_respon

我正在从weboage返回一个Excel.XLS文件,如:

xls_response = HttpResponse(mimetype='application/vnd.ms-excel')
xls_response['Content-Disposition'] = 'attachment; filename=funfile.xls'
.
.
<code to generate the file - already accomplished>
.
.
return xls_response
xls\u response=HttpResponse(mimetype='application/vnd.ms excel')
xls_响应['Content-Disposition']='附件;filename=funfile.xls'
.
.
<生成文件的代码-已完成>
.
.
返回xls\u响应

一切正常,但我想在发送之前查看文件大小,以便显示上次下载时的文件大小。我已经有了一个模型来存储它,但是我需要弄清楚如何从
xls\u响应对象
获取文件大小,然后再将其返回到客户端。除了二进制数据的
len()
之外,还有其他方法可以做到这一点吗?

请参见下面的代码,记住django只是python

from sys

sys.getsizeof(obj[, default]) #returns size of a python object.

谢谢你,詹姆斯。你给我指明了正确的方向。我不得不保存
sys.getsizeof(xls\u response.content)
由于某种原因,对象的大小不是其内容的全部大小,而是
HttpResonse.content
的大小。干杯