我在 jinja 模板中遇到問題。如果我有一個像這樣的物件'jsonobj':
{
"type": "test",
"people": [{"name": "bill", "age": 43}]
}
在我的模板中,我正在嘗試做一個 if like
{% if 'test' is jsonobj.type %}
<!-- some html here -->
{% else %}
<!-- some other html here -->
{% endif %}
但我收到一個錯誤:
jinja2.exceptions.TemplateSyntaxError: Encountered unknown tag 'endfor'. You probably made a nesting mistake. Jinja is expecting this tag, but currently looking for 'elif' or 'else' or 'endif'. The innermost block that needs to be closed is 'if'.
當我在周圍添加卷曲時,jsonobj.type我得到
jinja2.exceptions.TemplateSyntaxError: expected token 'name', got '{'
正在查看這里的檔案,我認為它應該可以作業......有什么想法嗎?謝謝
我嘗試了我能想到的任何變化;==、is、isin 等。嘗試將 json obj 包裝在一組和兩組卷曲中。做了很多谷歌搜索
uj5u.com熱心網友回復:
可能你忘記endif了最后的標簽嗎?
{% if 'test' is jsonobj.type %}
...
{% else %}
...
{% endif %}
uj5u.com熱心網友回復:
{% endif %} 你好像忘了關 if 博客
uj5u.com熱心網友回復:
我能夠通過確保空格/縮進是均勻的來解決這個問題。這似乎解決了問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/522044.html
