I have an SQL request that gives me all the data I need (in Python)
I made it so that I have a list of dictionaries, it looks like that:
data = [{
"jour_de_la_semaine": "0",
"nom_rue": "Avenue Rogier",
"total_lourd": 4464.676489954501,
"total_pieton": 366.75719346780005,
"total_velo": 1530.4361518144,
"total_voiture": 16283.220910553997
}, {
"jour_de_la_semaine": "1",
"nom_rue": "Avenue Rogier",
"total_lourd": 4689.496674622601,
"total_pieton": 719.5071498280998,
"total_velo": 6835.787324285102,
"total_voiture": 22114.002369259702
},
...,
...]
I put the variable in the return template so that I can use it on JavaScript.
I’m using this to do the list in JavaScript:
var data = '{{ all_data_rue|tojson }}';
I can easily see all the data with a simple console.log(data);
but its impossible for me to loop through it… It always return me characters per characters.
I’ve tried every single solutions I could find on the Net. I’ve also find a post where it has the exact same problem but the solution didn’t work…
I’d like to get dictionaries per dictionaries and not characters per characters.
Any solution?
2
Answers
By doing
You are setting
data
to a string representation ofall_data_rue
. If you want to access the information from Javascript, you can doInstead of:
Try:
or even just: