How do I load data from MongoDB to D3JS, with Jinja2 syntax?

531 views Asked by At

I want to represent some entries in a list from my MongoDB database, but I want to use Jinja2 syntax, to get retrieve the entries from my database, through Flask. E.g.:

var dataArray = [{% for entry in entries %}{{ entry.value }}, {% endfor %}];

d3.select("body")
    ...

I think the comma is required, to seperate the values in the array, but it would still render a last comma, which is not needed. How does one do this properly?

1

There are 1 answers

0
Neil Lunn On

On separate lines for clarity. It's still valid, but put all on one line if you wish.

var dataArray = [
{% for entry in entries -%}
   {{ entry.value }}
   {% if not loop.last %},{% endif %}
{%- endfor %}
];