How do I pass a lot of parameters to views in Django?
Posted
by Mark
on Stack Overflow
See other posts from Stack Overflow
or by Mark
Published on 2010-04-27T00:00:03Z
Indexed on
2010/04/27
0:23 UTC
Read the original article
Hit count: 525
I'm very new to Django and I'm trying to build an application to present my data in tables and charts. Till now my learning process went very smooth, but now I'm a bit stuck.
My pageview retrieves large amounts of data from a database and puts it in the context. The template then generates different html-tables. So far so good.
Now I want to add different charts to the template. I manage to do this by defining <img src=".../> tags.
The Matplotlib chart is generate in my chartview an returned via:
response=HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
Now I have different questions:
- the data is retrieved twice from the database. Once in the pageview to render the tables, and again in the chartview for making the charts. What is the best way to pass the data, already in the context of the page to the chartview?
- I need a lot of charts, each with different datasets. I could make a chartview for each chart, but probably there is a better way. How do I pass the different dataset names to the chartview? Some charts have 20 datasets, so I don't think that passing these dataset parameters via the url (like:
<imgm src="chart/dataset1/dataset2/.../dataset20/chart.png />
) is the right way.
Any advice?
© Stack Overflow or respective owner