0

I have a function, which renders my template when called:

def exampleTemplate():
    exampleData = getData()
    render_template(index.html, data=exampleData)

And I have something like an API, which is called from other sites. It manipulates the exampleData in exampleTemplate.

def exampleAPI():
    manipulateExampleData()
    return json()

How do I refresh the data with Ajax in exampleTemplate whenever the exampleData is manipulated via exampleAPI()?

JohnDole
  • 525
  • 5
  • 16

1 Answers1

0

If you need to refresh as soon as exampleAPI is called you will need to use sockets, so you can send data from the server to the browser without the browser asking for it. Check out flask-socketio.

If you don't want to deal with sockets you can use polling, where you make an ajax request to a new route that gives you exampleData every few seconds or so. Then you can replace the data in your html with the new exampleData. See this post for details on how to do that with jQuery.