开发者

Dictionary literals in Mako expressions

The following throws a syntax error, "unexpected EOF while parsing":

${foo({'bar':'baz'})}

which I guess is from the inner closing curly brace. This works fine:

${foo(dict(bar='baz'))}

but what开发者_如何学编程's the syntax for using a dictionary literal?


From Brian Rue on the Mako Templates Google Group:

This is a long-outstanding bug; just use dict(). If you need a dictionary with keys that aren't strings, convert a list of tuples into a dict. e.g. instead of this:

${foo({1: 'a', 2: 'b'})}

do this:

${foo(dict([(1, 'a'), (2, 'b')]))}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜