I have a python flask app that I need to create a java script bar chart. I have tried various ways and I know my variables are getting passed to the html file as I have moved them to other places in the html file and its working. The place I need to pass these variables to is under the script tag in the html file. I am new to all of this and is there some special handling i need to do to make my variables show up, so the chart can be built?
Not sure if it matters but the variables I am passing is just a date and number.
# this is my python route that calls a function that fetches a date and a
# number from mongodb. This data im trying to display in my graph.
@app.route('/meritgraph/')
def meritgraph():
score_graph_data, score_date = get_chart_data()
return render_template("graphing.html", chart_data=zip(score_date,
score_graph_data))
# This is working for me but I want this to run inside a javascript tag.
<ol>{% for score_date, score_graph_data in chart_data %}
<li>{{score_date|safe}} and {{score_graph_data}}</li>
{% endfor %}
</ol>{%endblock%}
# for the example above I get the following return output.
Wed May 24 18:11:01 PDT 2017 and 100
Tue May 23 14:39:27 PDT 2017 and 77
Tue May 23 14:14:02 PDT 2017 and 62
# This is what I would like to do inside the script tag. Some reason when I
# run it inside the script tag it wont work. Is there anything special I
# need to do here?
<script type="text/javascript">
<ol>{% for score_date, score_graph_data in chart_data %}
<li>{{score_date|safe}} and {{score_graph_data}}</li>
{% endfor %}
</ol>{%endblock%}
</script>