k99
k99

Reputation: 749

How to render file-based template with arguments?

from mako.template import Template

stext = "hi"

mytemplate = Template(filename='./t.txt')
print mytemplate.render()

t.txt:

${hi}  , i am here

Upvotes: 1

Views: 429

Answers (1)

Dhaivat Pandya
Dhaivat Pandya

Reputation: 6536

Replace the last line with:

mytemplate.render(hi = "world")

Now, hi can equal anything you like, not just "world".

Upvotes: 2

Related Questions