a survey about how to make a file dynamically and offer it to download,but still not save the file!
To trigger a download you need to set Content-Disposition header:
from django.http importHttpResponse
from django.core.servers.basehttp importFileWrapper
# generate the file
response =HttpResponse(FileWrapper(myfile), content_type='application/zip')
response['Content-Disposition']='attachment; filename=myfile.zip'
return response
If you don't want the file on disk you need to use StringIO
import cStringIO asStringIO
myfile =StringIO.StringIO()
while not_finished:
# generate chunk
myfile.write(chunk)
Optionally you can set Content-Length header as well:
response['Content-Length']= myfile.tell()
http://djangosnippets.org/snippets/365/
http://djangosnippets.org/snippets/15/
this is a simple example to make a PDF file dynamically and offer to download!
https://docs.djangoproject.com/en/dev/howto/outputting-pdf/