'How to ignore html tags/code stored in JavaScript variables?

Hi I am currently working on a django project wherein I send multiple plotly charts as html code to the client side and try to store this html code in a dictionary I first make the chart and convert to HTML code

prediction_graph = prediction_graph.to_html(full_html=False)

then I send multiple such charts to client side. Here please note that charts itself is a dictionary.

return render(request, 'charts.html', {
                "tickerList": charts["tickerList"],
                "charts": json.dumps(charts)})

On client side I try to store it in a javascript variable

charts = {{ charts|safe }};

However the html tags/code present in this variable causes error. enter image description here

enter image description here

Is there any way to solve this? like make it ignore the html tags/code



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source