Pushing updates from Python server to a web interface

后端 未结 1 1214
旧时难觅i
旧时难觅i 2021-01-18 09:35

I\'ve written an algorithm in python and a web interface around that. After you submit the form and start the algorithm, I\'d like to push and update data on the page as it\

1条回答
  •  离开以前
    2021-01-18 09:52

    To have real-time or semi-real time communications between the web page the options are

    • Automatically refresh the page after certain seconds using meta refresh tag in HTML

    • Fetch updated data with JavaScript and AJAX HTTP GET: https://api.jquery.com/jquery.get/

    • Use server-sent sent events: http://www.html5rocks.com/en/tutorials/eventsource/basics/

    • Use WebSockets: http://www.html5rocks.com/en/tutorials/websockets/basics/

    All approaches, excluding the first one, require rudimentary JavaScript skills besides knowing server-side Python. The latter two approaches recommend advanced understanding of real-time communications. Thus, if you are not familiar with the web development I recommend picking the meta refresh tag.

    On the server side you need to start a process or a thread which to handle the long running process, then have this process to write its progress to a database. When the web UI updates itself, it reads the latest results from the database and pushes/pulles them back to the browser.

    0 讨论(0)
提交回复
热议问题