无法在Django模板中解析布尔运算符的其余部分

发布于 2025-02-13 11:23:59 字数 220 浏览 0 评论 0 原文

如何在Django模板中使用布尔操作员?我想做类似的事情:

{% if forloop.counter<=12 or forloop.counter>=25 %}

但是它给了我一个错误:

无法从'forloop.counter&lt; = 12'

中解析剩余的:'&lt; = 12'

How can I use a boolean operator in django template? I want to do something like:

{% if forloop.counter<=12 or forloop.counter>=25 %}

But it is giving me an error:

Could not parse the remainder: '<=12' from 'forloop.counter<=12'

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

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

发布评论

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

评论(3

肥爪爪 2025-02-20 11:23:59

通过保持空间操作员来尝试此操作。

{% if forloop.counter <= 12 or forloop.counter >= 25 %}

Try this by keeping space around operator

{% if forloop.counter <= 12 or forloop.counter >= 25 %}
想念有你 2025-02-20 11:23:59

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

抹茶夏天i‖ 2025-02-20 11:23:59

如果操作员周围缺乏空格,Django模板使用的解析器将无法解析值。有一个 ticket#27022 在Django的问题跟踪器上开放,但已被标记为“ Wontfix”为了在模板中执行一致的样式。

因此,您需要更新代码并添加操作员周围的空间:

{% if forloop.counter <= 12 or forloop.counter >= 25 %}

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:

{% if forloop.counter <= 12 or forloop.counter >= 25 %}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文