I have a very similar problem to this question, Python datastructures into js datastructures using Django templates (lists and dicts) but with the next step - how do the variable names in python that are strings become javascript objects?
So in python I have this:
data = [{'year': 2006, 'books': 54, 'author': 'fred'},
{'year': 2007, 'books': 43, 'author': 'sue'},
{'year': 2008, 'books': 41, 'author': 'bill'},
{'year': 2009, 'books': 44, 'author': 'alex'},
{'year': 2010, 'books': 35, 'author': 'fred'}]
which I can output into my javascript via {{ data | safe }}
but I would like my javascript to look like this:
var data = [{year: 2006, books: 54, author: 'fred'},
{year: 2007, books: 43, author: 'sue'},
{year: 2008, books: 41, author: 'bill'},
{year: 2009, books: 44, author: 'alex'},
{year: 2010, books: 35, author: 'fred'}];
whereas it comes out at the moment like this:
var data = [{'year': 2006, 'books': 54, 'author': 'fred'},
{'year': 2007, 'books': 43, 'author': 'sue'},
{'year': 2008, 'books': 41, 'author': 'bill'},
{'year': 2009, 'books': 44, 'author': 'alex'},
{'year': 2010, 'books': 35, 'author': 'fred'}];
Is there anyway to do this?
Many thanks, Mark