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 8080683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:29:25+00:00 2026-06-05T16:29:25+00:00

I have a django view generating a bunch of data which I want to

  • 0

I have a django view generating a bunch of data which I want to break down into three different charts to be displayed in a template. I can generate the charts one by one and do a simple return HttpResponse() to determine I’m creating them with the right data, etc.

Since this is the first time I’ve used ReportLab, I want to make sure I’m taking the right approach with generating these for presentation in a web app. I can see two different ways to handle this:

  1. Actually pass the binary representation of the charts to the template and assign them to an img tag. (Unfortunately, I’ve been unsuccessful at this so far – when I dump the binary data in the template, it’s empty)

    1. Save the charts as images and reference the static images in the template.

I’m looking for some advice on which approach to take and if possible, some hints at implementation.

For reference, here’s a snippet from the view producing the charts (much of this was built from the DjangoProject wiki sample):

#instantiate a drawing object
import mycharts
d = mycharts.MyBarChartDrawing(width=800, height=500)

d.chart.categoryAxis.categoryNames = ['Pre-Operative Visit', '6-Week Visit', '3-Month Visit ', '6-Month Visit', '12-Month Visit']
d.chart.data = vas_scores_wrapper   

#get a GIF (or PNG, JPG, or whatever)
image_data = d.asString('png')

return HttpResponse(image_data, 'image/gif')
return render_to_response('summaries/study_summary.html', {'patients':patient_list,'query_form':query_form,'image_data':image_data}, context_instance=RequestContext(request)) 

This will work to produce a BarChart. FWIW, passing ‘image_data’ to the template and dumping it on that template wasn’t displaying anything. Perhaps you can’t pass binary data directly to a template?

  • 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-05T16:29:27+00:00Added an answer on June 5, 2026 at 4:29 pm

    I would save the images to the Media directory and pass their paths to the template to be used in img.href. This would help you cache charts for multiple use and make your life easier when debugging.

    However you could always try to do base64 encoding of the images and pass them as binaries to the template but this would make your html slightly larger when rendering (read slow) and requires extra efforts in debugging when you need to. I recommend the first option.

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

Sidebar

Related Questions

I have a Django view, which receives part of its data from an external
I have a Django project. Given a url, how can I know which view
I have a Django view that receives POSTs which do not need to have
I have a Django application which sometimes needs to send some data through TCP
I have a Django 'add business' view which adds a new business with an
I have a Django view which returns an HttpResponse with a special MIME type
I have a Django view that returns a list of dicts like so data
I have a django view that I want to return an Excel file. The
I have a django view which uses a template to display a long queryset
I have a Django form which I'm validating in a normal Django view. I'm

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.