Compare commits
2 Commits
ae74d84983
...
8a15a29dcf
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a15a29dcf | |||
| 11e4e393e8 |
30
app.py
30
app.py
@@ -1,4 +1,4 @@
|
|||||||
from flask import Flask, jsonify, request, render_template
|
from flask import Flask, jsonify, request, render_template, redirect
|
||||||
|
|
||||||
compiti = [
|
compiti = [
|
||||||
{"id": 1, "descrizione": "Compito matematica"},
|
{"id": 1, "descrizione": "Compito matematica"},
|
||||||
@@ -48,4 +48,32 @@ def delete_compito(id):
|
|||||||
return jsonify(ciscomerda), 200
|
return jsonify(ciscomerda), 200
|
||||||
return jsonify([]), 404
|
return jsonify([]), 404
|
||||||
|
|
||||||
|
@app.route("/ui")
|
||||||
|
def web_ui():
|
||||||
|
# Tabella compiti
|
||||||
|
html = "<table border>"
|
||||||
|
for ciscomerda in compiti:
|
||||||
|
html += "<tr>"
|
||||||
|
html += f"<td>{ciscomerda["descrizione"]}</td>"
|
||||||
|
html += "</tr>"
|
||||||
|
html += "</table>"
|
||||||
|
|
||||||
|
html += "<form action=\"/form_add\">"
|
||||||
|
html += "<input type=\"text\" name=\"descrizione\" placeholder=\"Descrizione compito\">"
|
||||||
|
html += "<input type=\"submit\" value=\"Aggiungi compito\">"
|
||||||
|
html += "</form>"
|
||||||
|
|
||||||
|
return html, 200
|
||||||
|
|
||||||
|
@app.route("/form_add")
|
||||||
|
def form_add():
|
||||||
|
if not request.args.get("descrizione"):
|
||||||
|
return "Errore: descrizione mancante", 400
|
||||||
|
else:
|
||||||
|
global id_counter
|
||||||
|
d = request.args.get("descrizione")
|
||||||
|
compiti.append({"id": id_counter, "descrizione": d})
|
||||||
|
id_counter += 1
|
||||||
|
return redirect("/ui")
|
||||||
|
|
||||||
app.run("0.0.0.0")
|
app.run("0.0.0.0")
|
||||||
|
|||||||
Reference in New Issue
Block a user