Sumant Agnihotri
Sumant Agnihotri

Reputation: 522

How to download content from my Django webpage?

I have a table on one of my Django webpage. I want to give the user the ability to download the content of the table in xl format. What would be an efficient and good way of doing this?

I was thinking of creating an xlsx file using the xldr library. Writing the data on the file. making the file available for download and then deleting the file at the end, so that my drive stays clean.

but it doesn't feel like a very efficient way. I'm new in web development, so open to all kind of ideas. Thanks

Upvotes: 0

Views: 87

Answers (1)

nigel222
nigel222

Reputation: 8192

There's an example in the python doc of generating a pdf response. Apart from using xldr I don't suppose it needs to be much different, though I haven't done this. It uses io.BytesIO in-memory buffering to avoid creating temporary files, and sends that back using FileResponse instead of HttpResponse

Upvotes: 1

Related Questions