I have the following:
views.py:
return render_template('test.html',
title='Home',
labels = output_labels)
test.html:
<script src="{{ url_for('static', filename='js/demo.js') }}"></script>
<script type="text/javascript">
var labelsx = {{ labels|tojson }};
</script>
demo.js:
Chartist.Pie('#chartPreferences', {
labels: ['{{labelsx}}'],
series: [62, 32, 6]
});
It looks like that demo.js is not recognizing the labelsx variable at all (tried without brackets as well). The labelsx variable before "tojson" is a list:
print type(output_labels)
print output_labels
<type 'list'>
[u'string1', u'string2', u'string3']
What am I doing wrong ?
EDIT: In my opinion it is different to Passing variables from flask to javascript since I had suggested code already in place and as per accecpted answer here, the problem was in the order of defining the variable used by .js later on - which is not mentioned in that older question. Thanks !