Код: Выделить всё
% template.tmpl file:
% set result = fractions.Fraction(a*d + b*c, b*d) %}
The solution of ${{a}}/{{b}} + {{c}}/{{d}}$ is ${{a * d + b*c}}/{{b*d}} = {{result.numerator}}/{{result.denominator}}$
Код: Выделить всё
from jinja2 import Template
import fractions
with open("c.jinja") as f:
t = Template(f.read())
a = 2
b = 3
c = 4
d = 5
print(t.render(a = a, b = b, c=c, d=d))
Код: Выделить всё
jinja2.exceptions.UndefinedError: 'fractions' is undefined
Код: Выделить всё
The solution of $2/3 + 4/5$ is $22/15=22/15$.
Подробнее здесь: https://stackoverflow.com/questions/786 ... -templates