From aea2e194536c67b7a1a478c4f38e189653f32e2d Mon Sep 17 00:00:00 2001 From: fenix Date: Tue, 13 Feb 2024 16:30:14 +0100 Subject: [PATCH] ++ extendido base.html -> resultados TPL --- app.py | 25 +++++++++++++++++++++++-- templates/base.html | 8 ++++---- templates/results.html | 15 +++++---------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/app.py b/app.py index 18a3fee..7146db0 100644 --- a/app.py +++ b/app.py @@ -1,10 +1,31 @@ -from flask import Flask +from flask import Flask, render_template app = Flask(__name__) @app.route("/") 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__": app.run(debug=True) diff --git a/templates/base.html b/templates/base.html index baeab16..c4f25fb 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,12 +5,12 @@ - {{ title }} + {% block title %}{{ title }}{% endblock title %} - -

Welcome to {{ title }}!

- + {% block content %} +

Welcome to {{ title }}!

+ {% endblock content %} diff --git a/templates/results.html b/templates/results.html index c90ac5a..b81fe85 100644 --- a/templates/results.html +++ b/templates/results.html @@ -1,14 +1,10 @@ {# templates/results.html #} - - - - - Results - +{% extends "base.html" %} - -

{{ test_name }} ResultadOS:

+{% block content %} + +

{{ test_name }} {{ title }}:

- - +{% endblock content %}