W
W
Wolf_Yout2022-04-04 22:43:50
Python
Wolf_Yout, 2022-04-04 22:43:50

How to make site update every 10 seconds?

I made this nonsense:

@app.route("/chat")
def _chat():
    with open("db/lastauthor.txt", "r") as file:
        author = file.read()
    with open("db/lastmsg.txt", "r") as file:
        content = file.read()
    return render_template("chat.html", author=author, content = content)

And I need this "nonsense" to be updated every 10 seconds, this is necessary so that I do not have to reload the page to check the last message

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Leonid, 2022-04-04
@bravebug

this is usually implemented in JavaScript (Flask will return a fresh page at any time, and the browser should force something to automatically reload the page)
https://www.w3docs.com/snippets/javascript/how-to-...

A
Alexander Nesterov, 2022-04-05
@AlexNest

Use sockets.
They allow you to create a streaming connection between the client and the server, which in turn.

  • will allow the server to tell the front in real time that it needs to update the data on the page.
  • will reduce resource consumption (supporting a single connection instead of processing dozens of requests)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question