How To Reference Multi-word Dictionary Key In Mako?
I am passing a csv file to Mako via csv.DictReader, and the dictionary uses row headers for keys. Some of these have names like 'Entry Id'. Mako throws out errors when I try to ref
Solution 1:
I have found one way that works, but I'd rather send the dictionary as **kwargs if possible. Here is the working solution:
from mako.template import Template
mydata = {'foo': 'bar', 'better foo': 'beach bar'}
working_template = Template("Let's go to the ${foo}")
fail_template = Template("Let's go to the ${mydata['better foo']}")
print working_template.render(**mydata)
print fail_template.render(mydata=mydata)
Post a Comment for "How To Reference Multi-word Dictionary Key In Mako?"