I have a Django view that returns a list of names such as
data = [{'year': 2006, 'books': 54}, {'year': 2007, 'books': 43}, {'year': 2008, 'books': 41}, {'year': 2009, 'books': 44}, {'year': 2010, 'books': 35}] c = { 'data': data, } return render(request, 'template.html', c)
There is some basic JavaScript in the template file that does something like this.
var data = "{{data}}"; console.log(data);
The problem is that the data comes in JavaScript through a template formatted as shown below: & # 39 for quotes.
{&
I tried dropping a list of dicts to a json string in python using:
simplejson.dumps(data)
But there is no joy. Any suggestions or ideas for a fix? How people get python datastructures in js datastructures using django templates
Note. Ideally, the js data variable would look like this:
var data = [{year: 2006, books: 54}, {year: 2007, books: 43}, {year: 2008, books: 41}, {year: 2009, books: 44}, {year: 2010, books: 35}];