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 = [
|
compiti = [
|
||||||
{"id": 1, "descrizione": "Compito matematica"},
|
{"id": 1, "descrizione": "Compito matematica"},
|
||||||
@@ -13,20 +13,12 @@ app = Flask(__name__)
|
|||||||
@app.route("/", methods=["GET"])
|
@app.route("/", methods=["GET"])
|
||||||
def home():
|
def home():
|
||||||
html = "<h1>Home page API REST Compiti</h1><h2>ciao, 3cx merda</h2>"
|
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
|
return html, 200
|
||||||
|
|
||||||
@app.route("/<path:filename>", methods=["GET"])
|
@app.route("/doc", methods=["GET"])
|
||||||
def template(filename):
|
def get_doc():
|
||||||
if not filename.endswith(".html"):
|
return render_template("doc.html"), 200
|
||||||
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("/compiti", methods=["GET"])
|
@app.route("/compiti", methods=["GET"])
|
||||||
def get_compiti():
|
def get_compiti():
|
||||||
|
|||||||
@@ -1 +1,8 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Documentazione</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
haiiiii :3
|
haiiiii :3
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user