Lazik
Lazik

Reputation: 2520

How to output unescaped python list in bottle template?

I have a bottle template home.tpl

<script>
function googleChart() {   
    google.load('visualization', '1', {packages: ['corechart']});

    function drawVisualization() {
        // Create and populate the data table.

        var data = google.visualization.arrayToDataTable({{net_data}});
        ... 
    }
}
</script> 
...

this is a bit of the python script:

test = "[['Year', 'Q1', 'Q2', 'Q3', 'Q4'], ['2005', 369193000.0, 342814000.0, 381182000.0,372208000.0], ['2006', 592291000.0, 721077000.0, 733361000.0, 1030717000.0], ...]"
return template('home', net_data=test)

I tried :

test = "[[],[],[]]"
test = [[],[],[]]
test = json.dumps([[],[],[]])

The html output ends up being encoded like this
[[&#039;Year&#039;, &#039;Q1&#039;, &#039;Q2&#039;, &#039;Q3&#039;],...]

What is the correct way to do this?

This is what I expect:

var data = google.visualization.arrayToDataTable([['Year', 'Q1', 'Q2', 'Q3', 'Q4'], ['2005', 369193000.0, 342814000.0, 381182000.0,372208000.0], ['2006', 592291000.0, 721077000.0, 733361000.0, 1030717000.0], ...]);

Upvotes: 2

Views: 435

Answers (1)

Ajay
Ajay

Reputation: 151

As Bottlepy SimpleTemplateEngine help states here http://bottlepy.org/docs/dev/stpl.html#inline-expressions

Try this

    var data = google.visualization.arrayToDataTable({{!net_data}});

Upvotes: 2

Related Questions