This is my FLASK variable {{ list_fruits }}
when I display it between the <body>
brakets in the browser I get :
<body>
{{ list_fruits }}
</body>
[ ['Bananas', 8], ['Kiwi', 3], ['Mixed nuts', 1],['Oranges', 6], ['Apples', 8] ]
But when I display it between the javascript <script>
brackets the Apostrophes
converts to '
so I get something like this:
<script>
{{ list_fruits }}
</script>
[ ['Bananas';, 8], ['Kiwi', 3], ['Mixed nuts', 1],['Oranges', 6], ['Apples', 8] ]
How to prevent javascript from transferring the Apostrophes
to '
?
Try {{ list_fruits|tojson|safe }}
to inject JSON data into your template.