++ extendido base.html -> resultados TPL

This commit is contained in:
fenix 2024-02-13 16:30:14 +01:00
parent 88c478081a
commit aea2e19453
3 changed files with 32 additions and 16 deletions

25
app.py
View File

@ -1,10 +1,31 @@
from flask import Flask from flask import Flask, render_template
app = Flask(__name__) app = Flask(__name__)
@app.route("/") @app.route("/")
def home(): def home():
return "HOLA, World!" return render_template("base.html", title= " HOLA Jinja + Flask :-)")
max_score = 100
test_name = "Py Reto "
students = [
{"name": "Sandrine", "score": 100},
{"name": "Gergeley", "score": 87},
{"name": "Frieda", "score": 92},
{"name": "Fritz", "score": 40},
{"name": "Sirius", "score": 75},
]
@app.route("/results")
def results():
context = {
"title": "Results",
"students": students,
"test_name": test_name,
"max_score": max_score,
}
return render_template("results.html", **context)
if __name__ == "__main__": if __name__ == "__main__":
app.run(debug=True) app.run(debug=True)

View File

@ -5,12 +5,12 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>{{ title }}</title> <title>{% block title %}{{ title }}{% endblock title %}</title>
</head> </head>
<body> <body>
{% block content %}
<h1>Welcome to {{ title }}!</h1> <h1>Welcome to {{ title }}!</h1>
{% endblock content %}
</body> </body>
</html> </html>

View File

@ -1,14 +1,10 @@
{# templates/results.html #} {# templates/results.html #}
<!DOCTYPE html> {% extends "base.html" %}
<html lang="en">
<head>
<meta charset="utf-8">
<title>Results</title>
</head>
<body> {% block content %}
<h1>{{ test_name }} ResultadOS: </h1>
<h1>{{ test_name }} {{ title }}: </h1>
<ul> <ul>
{% for student in students %} {% for student in students %}
<li> <li>
@ -17,5 +13,4 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
</body> {% endblock content %}
</html>