solución a Jj 'TemplateNotFound'
This commit is contained in:
parent
7bda9ca408
commit
ee87a0715a
|
@ -1,27 +0,0 @@
|
||||||
# good_messages.py
|
|
||||||
|
|
||||||
from jinja2 import Environment, FileSystemLoader
|
|
||||||
|
|
||||||
MAX_SCORE = 100
|
|
||||||
TEST_NAME = "Python Challenge"
|
|
||||||
|
|
||||||
students = [
|
|
||||||
{"name" : "Willow", "score":100},
|
|
||||||
{"name" : "Cordelia", "score":85},
|
|
||||||
{"name" : "Oz", "score":95},
|
|
||||||
]
|
|
||||||
|
|
||||||
env = Environment(loader=FileSystemLoader("templates/"))
|
|
||||||
template = env.get_template("good.txt")
|
|
||||||
|
|
||||||
for student in students:
|
|
||||||
name = student["name"]
|
|
||||||
filename = f"output/message_{name.lower()}.txt"
|
|
||||||
content = template.render(
|
|
||||||
student,
|
|
||||||
max_score=MAX_SCORE,
|
|
||||||
test_name=TEST_NAME
|
|
||||||
)
|
|
||||||
with open(filename, mode="w", encoding="utf-8") as output:
|
|
||||||
output.write(content)
|
|
||||||
print("... wrote", filename)
|
|
|
@ -1,9 +0,0 @@
|
||||||
{# templates/good.txt #}
|
|
||||||
Hello {{ name }},
|
|
||||||
|
|
||||||
I'm happy to inform you that you did very well on today's {{ test_name }}.
|
|
||||||
You achieved {{ score }} out of { max_score }} points !
|
|
||||||
|
|
||||||
see you tomorrow, nos vemos :-)
|
|
||||||
|
|
||||||
Ms. Hypyatia
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{# templates/message.txt #}
|
||||||
|
HOLA! {{ name }},
|
||||||
|
|
||||||
|
Estoy happy to inform you that you did very well on today's {{ test_name }}.
|
||||||
|
HAs alcanzado esta puntuación : {{ score }} de { max_score }} PUNTOS !
|
||||||
|
|
||||||
|
see you tomorrow, nos vemos :-)
|
||||||
|
|
||||||
|
Mr. JokerPy
|
|
@ -0,0 +1,25 @@
|
||||||
|
# write_messages.py
|
||||||
|
|
||||||
|
from jinja2 import Environment, FileSystemLoader
|
||||||
|
|
||||||
|
max_score = 100
|
||||||
|
test_name = "Python Challenge"
|
||||||
|
students = [
|
||||||
|
{"name": "Sandrine", "score": 100},
|
||||||
|
{"name": "Gergeley", "score": 87},
|
||||||
|
{"name": "Frieda", "score": 92},
|
||||||
|
]
|
||||||
|
|
||||||
|
environment = Environment(loader=FileSystemLoader("templates/"))
|
||||||
|
template = environment.get_template("message.txt")
|
||||||
|
|
||||||
|
for student in students:
|
||||||
|
filename = f"message_{student['name'].lower()}.txt"
|
||||||
|
content = template.render(
|
||||||
|
student,
|
||||||
|
max_score=max_score,
|
||||||
|
test_name=test_name
|
||||||
|
)
|
||||||
|
with open(filename, mode="w", encoding="utf-8") as message:
|
||||||
|
message.write(content)
|
||||||
|
print(f"... wrote {filename}")
|
Loading…
Reference in New Issue