javascript - using flask render_template to make a highchart on the front end -


i have simple python method generate highcharts json

@app.route('/make/a/chart') def make_chart():   data = get_data()   c = counter   each in data:     c['age'] += 1    highchart_json = {     'chart': {       'type': 'column'     }     'title': {       'text': 'arranged age'     }     'x-axis': {       'categories': [x x in c]     }     'series': {       'name': 'groups age',       'data': [c[x] x in c]     }   }   return render_template('some_template.html', json=highchart_json) 

is possible have render template, or real way turn highchart jsonifying , sendng front end?

you can put json template javascript structure:

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

and can use client-side in js code. json subset of javascript, after all, or @ least json produced python json module is.

this uses flask tojson filter, produces html safe json values; html-metacharacters escaped using json \uxxxx escape codes.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -