You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import logging
|
|
from flask import Flask, render_template, request
|
|
from flask_socketio import SocketIO, emit
|
|
|
|
app = Flask(__name__)
|
|
app.config['SECRET_KEY'] = 'geheimeschluessel'
|
|
socketio = SocketIO(app)
|
|
|
|
# Beispiel-Datenquelle
|
|
table_data = [
|
|
{"id": 1, "name": "Alice", "age": 25},
|
|
{"id": 2, "name": "Bob", "age": 30},
|
|
{"id": 3, "name": "Charlie", "age": 35}
|
|
]
|
|
|
|
# Konfiguriere das Logging
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html', table_data=table_data)
|
|
|
|
@app.route('/update_table', methods=['POST'])
|
|
def update_table():
|
|
updated_data = request.json
|
|
for row in updated_data:
|
|
row_id = row['id']
|
|
for entry in table_data:
|
|
if entry['id'] == row_id:
|
|
entry['name'] = row['name']
|
|
entry['age'] = row['age']
|
|
break
|
|
|
|
socketio.emit('table_update', table_data, broadcast=True)
|
|
logger.info('Daten aktualisiert: %s', table_data) # Logge die aktualisierten Daten
|
|
return 'Daten aktualisiert'
|
|
|
|
if __name__ == '__main__':
|
|
socketio.run(app)
|