John Martin
unread,Nov 6, 2009, 6:05:41 PM11/6/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Mako Templates for Python
Hi,
I'm a complete newbie to Mako and to templating in general. I'd like
to use Mako to create a report
where the length of certain elements in the report isn't known until
runtime.
To that end, I'd like to pass a list from my python code into a Mako
template, and have the
template loop over the elements in the list.
My python code is:
from mako.template import Template
my_dict = {}
my_dict['names'] = ['alice', 'bob']
t = Template(filename=fn)
print t.render(**my_dict)
where fn is the name of my template which contains:
% for name in ${names}:
${name}
% endfor
Running the code gives a mako.exceptions.SyntaxException at the first
line of the template.
I must be missing something very obvious here - why doesn't the
"names" list get substituted into ${names} in the for loop?
Thanks,
John