Modifica funzione lettura template per documentazione

This commit is contained in:
2026-02-20 09:44:43 +01:00
parent 0892f2aa49
commit d31a0fbef3
2 changed files with 13 additions and 14 deletions

18
app.py
View File

@@ -1,4 +1,4 @@
from flask import Flask, jsonify, request
from flask import Flask, jsonify, request, render_template
compiti = [
{"id": 1, "descrizione": "Compito matematica"},
@@ -13,20 +13,12 @@ app = Flask(__name__)
@app.route("/", methods=["GET"])
def home():
html = "<h1>Home page API REST Compiti</h1><h2>ciao, 3cx merda</h2>"
html += "<a href=\"/doc.html\">Documentazione</a>"
html += "<a href=\"/doc\">Documentazione</a>"
return html, 200
@app.route("/<path:filename>", methods=["GET"])
def template(filename):
if not filename.endswith(".html"):
return "File non valido", 404
try:
read_file = open(f"templates/{filename}", "r")
content = read_file.read()
read_file.close()
return content, 200
except FileNotFoundError:
return "File non trovato", 404
@app.route("/doc", methods=["GET"])
def get_doc():
return render_template("doc.html"), 200
@app.route("/compiti", methods=["GET"])
def get_compiti():

View File

@@ -1 +1,8 @@
haiiiii :3
<html>
<head>
<title>Documentazione</title>
</head>
<body>
haiiiii :3
</body>
</html>