django模板中是否可以使用布尔逻辑?

wil*_*low 14 python django templates boolean

我想做的事情如下:

{% if ("view_video" in video_perms) OR purchase_override %}
Run Code Online (Sandbox Code Playgroud)

那可能吗?

Spa*_*man 29

Django对布尔运算符的文档

给你:

{% if user in users %}
  If users is a QuerySet, this will appear if user is an
  instance that belongs to the QuerySet.
{% endif %}
Run Code Online (Sandbox Code Playgroud)

{% if a == b or c == d and e %}
Run Code Online (Sandbox Code Playgroud)

请注意,and优先级高于or,并且括号不可能.如果需要,使用嵌套块.

  • 为了遗嘱的自我接受+1 :)很高兴先生. (3认同)
  • 现在好了.这将是一个明智的地方.我确实在那里试过,但在我的手机上,我找不到我需要的位.谢谢您的帮助.抱歉,这个菜鸟问题. (2认同)