The Jinja template provides double quotes or single quotes like "

Hi, I tried to populate the Google visualization api in a jinja template. I took the parameters of the sample and passed it to the API but it converts single and double quotes to 'and & Here is the script:

<script type="text/javascript"> //load the Google Visualization API and the chart google.load('visualization', '1', {'packages': ['columnchart']}); //set callback google.setOnLoadCallback (createChart); //callback function function createChart() { //create data table object var dataTable = new google.visualization.DataTable(); //define columns dataTable.addColumn('string','Quarters 2009'); dataTable.addColumn('string', 'Earnings'); //define rows of data // answerjson=answerjson.replace("&#39;",'"'); {% set answerjson1='[["1": "Saturday"], ["6": "Sunday"], ["1": "Wednesday"], ["1": "Monday"], ["1": "Monday"], ["1": "Tuesday"], ["1": "Sunday"]' %} dataTable.addRows( {{answerjson1}} ); //instantiate our chart object var chart = new google.visualization.ColumnChart (document.getElementById('chart')); //define options for visualization var options = {width: 400, height: 240, is3D: true, title: 'Company Earnings'}; //draw our chart chart.draw(dataTable, options); } </script> 

Here is the input passed to the API I have put the screenshot because here it is rendered as double quotes

Please help me what I need to do.

+8
python jinja2
source share
1 answer

Use the safe filter:

 dataTable.addRows( {{ answerjson1 | safe }} ); 
+17
source share

All Articles