Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:21:14+00:00 2026-06-17T12:21:14+00:00

I’m using Django to create a web app where some parameters are input and

  • 0

I’m using Django to create a web app where some parameters are input and plots are created. I want to have a link which will be to download ALL the plots in a zip file. To do this, I am writing a view which will create all the plots (I’ve already written views that create each of the single plots and display them), then zip them up, saving the zip file as the response object.

One way I could do this is to create each plot, save it as a pdf file to disk, and then at the end, zip them all up as the response. However, I’d like to sidestep the saving to disk if that’s possible?

Cheers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:21:15+00:00Added an answer on June 17, 2026 at 12:21 pm

    This is what worked for me, going by Krzysiek’s suggestion of using StringIO. Here canvas is a canvas object created by matplotlib.

    #Create the file-like objects from canvases
    file_like_1 = StringIO.StringIO()
    file_like_2 = StringIO.StringIO()
    #... etc...
    canvas_1.print_pdf(file_like_1)
    canvas_2.print_pdf(file_like_2)
    #...etc....
    
    #NOW create the zipfile
    response = HttpResponse(mimetype='application/zip')
    response['Content-Disposition'] = 'filename=all_plots.zip'
    
    buff = StringIO.StringIO()
    archive = zipfile.ZipFile(buff,'w',zipfile.ZIP_DEFLATED)
    archive.writestr('plot_1.pdf',file_like_1.getvalue())
    archive.writestr('plot_2.pdf',file_like_2.getvalue())
    #..etc...
    archive.close()
    buff.flush()
    ret_zip = buff.getvalue()
    buff.close()
    response.write(ret_zip)
    return response
    

    The zipping part of all of this was taken from https://code.djangoproject.com/wiki/CookBookDynamicZip

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm interested in microtypography issues on the web. I want a tool to fix:
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.