I have this template:
% 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}}$
which I invoke by
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))
I get
jinja2.exceptions.UndefinedError: 'fractions' is undefined
but I want
The solution of $2/3 + 4/5$ is $22/15=22/15$.
Is this possible to achieve that?