0

Mako模板中,我需要执行以下操作:

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

当 A 这样做时,我收到此错误:

SyntaxException: (SyntaxError) 解析
(, line 1) ("'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'") in文件……</p>

我该如何解决这个问题?

我需要在翻译文本中使用这种语法:

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

2 回答 2

0

一种解决方法是以不同的方式传递 dict 对象。例如:

from mako.template import Template

print Template("${'foo %(a)s bar %(b)s' % data}").render(data=dict(a='Alpha',b='Beta'))
于 2010-02-08T14:25:16.883 回答
-1

解决方案:

${'foo %(a)s bar %(b)s' % dict((('a', '1'), ('b', '2'),))}
于 2010-02-08T14:47:03.680 回答