我已将我的代码从 webapp2 迁移到 Flask。(我在 Google App Engine 中部署我的代码)
但是,我不能再使用这个字符串:"Error: Max %1$d characters"
初始化
flask_app = Flask(__name__)
babel = Babel(flask_app, default_domain='strings')
html模板
<div class="...">{{ _('error_long_value') | replace('%1$d', '200') }}</div>
我知道这不是最好的用途,但我需要保留 %1$d 作为占位符。(它与 webapp2 一起工作)
日志:
...
File ".../libs/flask/templating.py", line 135, in render_template
context, ctx.app)
File ".../libs/flask/templating.py", line 117, in _render
rv = template.render(context)
File ".../libs/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File ".../libs/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File ".../app/templates/filename.html", line 567, in top-level template code
<div class="invalid-feedback">{{ _('error_long_value') | replace('%1$d', '200') }}</div>
ValueError: unsupported format character '$' (0x24) at index 29
我已经尝试在 HTML 模板中的“_('error_long_value')”之后使用“| e”或“| safe”,删除了 replace()。