Django Template - Convert python list into a javascript object

Posted by amcashcow on Stack Overflow See other posts from Stack Overflow or by amcashcow
Published on 2011-01-15T05:38:07Z Indexed on 2011/01/15 5:53 UTC
Read the original article Hit count: 160

I am working on a django / python website I have a page where I want to display a table of search results The list of results is passed in to the template as normal

I also want to make this list of objects accessible to the javascript code

My first solution was just create another view that returned json format. But each page load required calling the query twice. So then I tried only downloading the data using the json view and printing the table using javascript.

but this is also not desirable as now the presentation layer is mixed into the javascript code.

is there a way to create a javascript object from the python list as the page is rendered?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about python