为什么 Jinja2 将字符串渲染为“on”?为布尔值 True?
我将 Jinja2 与 YAML 结合使用,并具有以下结构:
{%- set example = [ (20, "on"), (40, "off")] %}
- name: example_yaml
loop:
{%- for value, state in example %}
- TheNumber: {{ value }}
TheState: {{ state }}
{%- endfor %}
呈现第一个循环时,TheNumber
与 20
是正确的,但 TheState
结束是True
。我查看了文档并尝试添加像这样的字符串过滤器:
{{ state | string }}
但这也不起作用。我还尝试将字符串 "on"
切换为 "StateShouldBeOn"
等其他内容以进行测试。这样我就得到了我所期望的TheState = "StateShouldBeOn"
。
我的问题是,为什么“on”呈现为布尔值?
I'm using Jinja2 with YAML and have the following structure:
{%- set example = [ (20, "on"), (40, "off")] %}
- name: example_yaml
loop:
{%- for value, state in example %}
- TheNumber: {{ value }}
TheState: {{ state }}
{%- endfor %}
When the first loop is rendered, TheNumber
is correct with 20
, but TheState
ends up being True
. I've looked through the documentation and have tried adding a string filter like this:
{{ state | string }}
But that did not work either. I have also Tried switching the string "on"
to something else like "StateShouldBeOn"
just to test with. With that I get what I expect TheState = "StateShouldBeOn"
.
My question is, why is it that "on" renders to a boolean value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用“on”而不是“on”。那应该有帮助。
Try to use 'on' instead of "on". That should help.