Search code examples
pythonhtmlflaskjinja2

Best way to check if variable in Jinja Template has changed?


I have a small python Flask application, which provides data for a basic HTML/Jinja frontend. It works perfectly fine to pass the data to the HTML file and iterate over it by using the Jinja template syntax. My problem is, that the served data can change any time, as the application is about showing kitchen staff what the customers ordered and there are new orders every few minutes.

So, now my question: Is there any way to check if a variable passed to a Jinja template from a Flask backend has changed? And if so, what's the best way to implement this?

I've already been through the Jinja docs, but found nothing.

Thanks in advance.


Solution

  • Jinja is a templating engine, which means that once you pass him the variables it renders them inside the specific template. Consequently, once this is done, the concept of variable no longer exists and to update the data within your page you have to adopt other solutions, such as: Flask Dynamic data update without reload page