문제

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.

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top