XlsxWriter object save as http response to create download in Django?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Django __str__ returned non-string (type NoneType)
- Evil ctypes hack in python
A little update on @alecxe response for Python 3 (io.BytesIO instead of StringIO.StringIO) and Django >= 1.5 (content_type instead of mimetype), with the fully in-memory file assembly that has since been implemented by @jmcnamara ({'in_memory': True}) !
Here is the full example :
When it comes to Django, you can even do without the whole
StringIO
shenanigans.HttpResponse
behaves just like a StringIO in that respect:Addendum: You need to specify
{'in_memory': True}
or you might getHttpResponse has no attribute seek()
. Thanks @JebI think you're asking about how to create an excel file in memory using
xlsxwriter
and return it viaHttpResponse
. Here's an example:Hope that helps.