【发布时间】:2011-06-10 08:15:06
【问题描述】:
我想做这样的事情:
{% if ("view_video" in video_perms) OR purchase_override %}
这可能吗?
【问题讨论】:
-
在某些时候,您应该为此使用模型和视图函数。为什么这不是模型对象的属性?还是登录用户的属性?
标签: python django templates boolean
我想做这样的事情:
{% if ("view_video" in video_perms) OR purchase_override %}
这可能吗?
【问题讨论】:
标签: python django templates boolean
Django docs on boolean operators
给你:
{% if user in users %}
If users is a QuerySet, this will appear if user is an
instance that belongs to the QuerySet.
{% endif %}
和
{% if a == b or c == d and e %}
请注意and 的优先级高于or,并且不能使用括号。如果需要,请使用嵌套块。
【讨论】:
if 构造只能在 Django 1.2 及更高版本中使用(参见 the release notes)