开发者

The ${'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'}} syntax doesn't work in a Mako template

开发者 https://www.devze.com 2022-12-19 18:15 出处:网络
In 开发者_如何学编程a Mako template, I need to do something like: ${\'foo %(a)s bar %(b)s\' % {\'a\': \'1\', \'b\': \'2\'}}

In 开发者_如何学编程a Mako template, I need to do something like:

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

When A do that, I get this error:

SyntaxException: (SyntaxError) unexpected EOF while parsing

(, line 1) ("'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'") in file…

How do I fix this issue?

I need to use this syntax in translated text:

$(_(u'foo bar %(a)s ... %(b)s) % { ... })


A work-around is to pass the dict object in a different way. For example:

from mako.template import Template

print Template("${'foo %(a)s bar %(b)s' % data}").render(data=dict(a='Alpha',b='Beta'))


Solution:

${'foo %(a)s bar %(b)s' % dict((('a', '1'), ('b', '2'),))}
0

精彩评论

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