Frage

How do I take the 'log' of a particular variable "testvar" in a Mako template? Assume that testvar is already a number. It does not appear clear in the documentation as to how one would do this.

War es hilfreich?

Lösung

You can import math inside the template, then call math.log:

>>> from mako.template import Template
>>> print Template("<%import math%>${math.log(testvar)}").render(testvar=2)
0.69314718056
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top