Skip to content Skip to sidebar Skip to footer

Using Flask Render_template To Make A Highchart On The Front End

I have a simple python method which will generate a highcharts json @app.route('/make/a/chart') def make_chart(): data = get_data() c = Counter for each in data: c['AGE']

Solution 1:

You can put JSON into a template as a Javascript structure:

<scripttype="text/javascript">var chart_data = {{ highchart_json|tojson|safe }};
</script>

and you can then use this client-side in your JS code. JSON is a subset of JavaScript, after all, or at least the JSON produced by the Python json module is.

This uses the Flask tojson filter, which produces HTML safe JSON values; any HTML-metacharacters are escaped for you using JSON \uxxxx escape codes.

Post a Comment for "Using Flask Render_template To Make A Highchart On The Front End"