Injecting data into javascript with Python Flask

hangc

I am following the instructions from http://www.highcharts.com/docs/getting-started/your-first-chart to create a sample chart. I have saved the main chunk of javascript locally, and am add the <script src="/chart.js"></script> tag in my html to reference it.

On my side, I am using python flask to render a html template containing the script.

@app.route('/view', methods=['POST', 'GET'])
def show_graph_view():
    query= request.form['query']
    data = get_current_data(query)
    return render_template('graph.html', data=data)

I have a function to prepare some custom and current data I want to plot instead and I want the data to be available once the client brower loads. How do I add this data into the charts?

Robert Moskal

Assuming a globally accessible function, just call it in the module with the data converted to json on the server with the tojson and safe filters.

<script type=text/javascript> doSomethingWith({{ data|tojson|safe }}); </script>

It's a bit hard to follow the logic when you mix together server side templating and client side scripting like this. But sometimes you gotta do it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Injecting data in html with javascript

From Dev

Python - injecting data into for loop

From Dev

Pass data from Python (flask framework) to javascript

From Dev

Injecting HTML5 data attributes vs. Injecting javascript data structure

From Dev

Injecting data into a Durandal widget

From Dev

Injecting data into root component

From Dev

Injecting Javascript bridge in WebView

From Dev

injecting javascript in my html

From Dev

Injecting Javascript bridge in WebView

From Dev

Flask - Getting JavaScript and Python to Communicate

From Dev

Return javascript variable in Python / Flask

From Dev

Python to Javascript JSON objects (Flask)

From Dev

Return javascript variable in Python / Flask

From Dev

Injecting data into jQuery $.getScript call

From Dev

Spring : injecting data object in service

From Dev

Is it possible to print the data from a text file to a html page via javascript or python(Flask)?

From Dev

Injecting JavaScript via browser extension

From Dev

Injecting a JavaScript script using Selenium Driver + PhantomJS and handling the redirection correctly in Python

From Dev

Python injecting random number into tests

From Dev

Python Flask get json data to display

From Dev

Python Flask Save Form Data to DB

From Dev

Python NoneTypeDataType while posting data to Flask with Ajax

From Dev

Data in Flask web app not updating [Python]

From Dev

Python flask-migrate data migration not saved

From Dev

Python Flask - Add POST data to sqlite database

From Dev

How to access html data in python flask

From Dev

JavaScript onload not recognized in extended html python flask

From Dev

Pass parameter with Python Flask in external Javascript

From Dev

Passing parameters from python/flask to javascript

Related Related

  1. 1

    Injecting data in html with javascript

  2. 2

    Python - injecting data into for loop

  3. 3

    Pass data from Python (flask framework) to javascript

  4. 4

    Injecting HTML5 data attributes vs. Injecting javascript data structure

  5. 5

    Injecting data into a Durandal widget

  6. 6

    Injecting data into root component

  7. 7

    Injecting Javascript bridge in WebView

  8. 8

    injecting javascript in my html

  9. 9

    Injecting Javascript bridge in WebView

  10. 10

    Flask - Getting JavaScript and Python to Communicate

  11. 11

    Return javascript variable in Python / Flask

  12. 12

    Python to Javascript JSON objects (Flask)

  13. 13

    Return javascript variable in Python / Flask

  14. 14

    Injecting data into jQuery $.getScript call

  15. 15

    Spring : injecting data object in service

  16. 16

    Is it possible to print the data from a text file to a html page via javascript or python(Flask)?

  17. 17

    Injecting JavaScript via browser extension

  18. 18

    Injecting a JavaScript script using Selenium Driver + PhantomJS and handling the redirection correctly in Python

  19. 19

    Python injecting random number into tests

  20. 20

    Python Flask get json data to display

  21. 21

    Python Flask Save Form Data to DB

  22. 22

    Python NoneTypeDataType while posting data to Flask with Ajax

  23. 23

    Data in Flask web app not updating [Python]

  24. 24

    Python flask-migrate data migration not saved

  25. 25

    Python Flask - Add POST data to sqlite database

  26. 26

    How to access html data in python flask

  27. 27

    JavaScript onload not recognized in extended html python flask

  28. 28

    Pass parameter with Python Flask in external Javascript

  29. 29

    Passing parameters from python/flask to javascript

HotTag

Archive