0

I am setting up a GUI server using Flask. I use an API which calls a function whenever a change in a particular Sqlite3 database, I then need to add the changed values to a table on the HTML page.

I have tried learning JQuery but that seems to require a get request coming from the client side. I need all the data that was added or changed in the database on the server-side to be appended to a table on the client page.

<tbody>
    {% for data in table_data %}
        <tr>
            <td>{{ loop.index }}</td>
            <td>{{ data[0] }}</td>
            <td>{{ data[1] }}</td>
            <td>{{ data[2] }}</td>
            </tr>
     {% endfor %}
</tbody>
def get_data(cursor_obj, table_name, previous_data):

    "When called will all the data from the db and will compair it to 
    the old data and return the data to be appended, which I then need 
    to add to the table."

    cursor_obj.execute("SELECT * FROM "+str(table_name))
    data = cursor_obj.fetchall()

    for old in previous_data:
        index = data.index(old)
        data.del(index)

    return data
shrys
  • 5,860
  • 2
  • 21
  • 36

1 Answers1

0

Without any client side request, that is going to be complicated. The information that the sqlite database changed can't just teleport from your server to the client by magic.

However, there are other solutions than polling the server at regular intervals from the client to check if information has changed: you can keep a connection from server to client open, and push notifications there.

The easiest way to implement this on the web is with "Server Sent Events".

You can check How to implement server push in Flask framework? for more information

Eloims
  • 5,106
  • 4
  • 25
  • 41