Modifica funzione lettura template per documentazione
This commit is contained in:
18
app.py
18
app.py
@@ -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():
|
||||
|
||||
@@ -1 +1,8 @@
|
||||
haiiiii :3
|
||||
<html>
|
||||
<head>
|
||||
<title>Documentazione</title>
|
||||
</head>
|
||||
<body>
|
||||
haiiiii :3
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user