${'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'}} 语法在 Mako 模板中不起作用

发布于 2024-08-20 19:59:21 字数 485 浏览 2 评论 0原文

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

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

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

SyntaxException:(SyntaxError)解析时出现意外的 EOF
(, 第 1 行) ("'foo %(a)s bar %(b)s' % {'a': '1', 'b': '2'") 在文件中...

如何解决此问题?

我需要在翻译文本中使用以下语法:

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

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) % { ... })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

面犯桃花 2024-08-27 19:59:21

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

from mako.template import Template

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

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'))
独自←快乐 2024-08-27 19:59:21

解决方案:

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

Solution:

${'foo %(a)s bar %(b)s' % dict((('a', '1'), ('b', '2'),))}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文