无法在Django模板中解析布尔运算符的其余部分
如何在Django模板中使用布尔操作员?我想做类似的事情:
{% if forloop.counter<=12 or forloop.counter>=25 %}
但是它给了我一个错误:
无法从'forloop.counter&lt; = 12'
中解析剩余的:'&lt; = 12'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过保持空间
操作员
来尝试此操作。Try this by keeping space around
operator
,我认为问题是您忘记了操作员的空间和变量。
foorloop.counter&lt; = 12
https://docs.djangoproject.com/es/1.10/ref/templates/builtins/#id4, i think the problem is that you forgot the space betwen the operator and the variable.
foorloop.counter <= 12
如果操作员周围缺乏空格,Django模板使用的解析器将无法解析值。有一个 ticket#27022 在Django的问题跟踪器上开放,但已被标记为“ Wontfix”为了在模板中执行一致的样式。
因此,您需要更新代码并添加操作员周围的空间:
The parser used by Django templates fails to parse the values if there is a lack of whitespace around the operators. There was a ticket #27022 opened on Django's issue tracker but it has been marked as "wontfix" in an effort to enforce a consistent style in templates.
Hence you need to update your code and add spaces around the operators: