Search code examples
pythoncherrypycheetah

Cheetah template engine calling python base function


I am using Cheetah template together with Cherrypy, below is my main python file

Main.py:
def multiple(a,b):
    return a*b

def index(self):
    t = Template('template.tmpl')
    #blah implementation here

In my template file, I wish to achieve

<body>
    <div>
       $multiple(2,3)
    </div>
</body>

Anyone has an idea how can I get this implement? Many thanks.

Regards, Andy.


Solution

  • t = Template("template.tmpl")
    t.multiple = multiple
    

    That should do the trick.