Search code examples
pythonmako

How to use log in Mako?


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.


Solution

  • 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