CARVIEW |
Select Language
HTTP/2 200
server: nginx
content-type: text/html;charset=utf-8
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
set-cookie: trac_form_token=11239c3be8e0acb1acb35ad4; HttpOnly; Path=/; Secure
set-cookie: trac_session=c7c0266aa88d46f472d242f9; expires=Tue, 21 Oct 2025 14:01:23 GMT; HttpOnly; Path=/; Secure
strict-transport-security: max-age=31536000; includeSubDomains; preload
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
accept-ranges: bytes
via: 1.1 varnish, 1.1 varnish
date: Wed, 23 Jul 2025 14:01:23 GMT
x-served-by: cache-fra-eddf8230071-FRA, cache-bom-vanm7210061-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753279283.066852,VS0,VE325
vary: Accept-Encoding
CookBookDynamicZip – Django
Back to Top
Django
The web framework for perfectionists with deadlines.
Issues
Return a dynamically created zip file in your HttpResponse.
import zipfile from cStringIO import StringIO from django.utils.httpwrappers import HttpResponse def view_that_returns_zipped_file(request): response = HttpResponse(mimetype='application/zip') response['Content-Disposition'] = 'filename=all_things.zip' #first assemble your files files = [] for thing in Thing.objects.all(): files.append(("%s.pdf" % (thing.id,), thing.biggish_file())) #now add them to a zip file #note the zip only exist in memory as you add to it buffer = StringIO() zip = zipfile.ZipFile(buffer, "w", zipfile.ZIP_DEFLATED) for name, f in files: zip.writestr(name, f) zip.close() buffer.flush() #the import detail--we return the content of the buffer ret_zip = buffer.getvalue() buffer.close() response.write(ret_zip) return response
Last modified
19 years ago
Last modified on Aug 21, 2006, 7:11:18 AM
Note:
See TracWiki
for help on using the wiki.
Download in other formats:
Django Links
Learn More
Get Involved
Follow Us
- Hosting by In-kind donors
- Design by Threespot &
© 2005-2025 Django SoftwareFoundation unless otherwise noted. Django is a registered trademark of the Django Software Foundation.