Is boolean logic possible in django templates?


Question

I want to do something like:

{% if ("view_video" in video_perms) OR purchase_override %}

Is that possible?

1
14
1/17/2011 11:41:52 AM

Accepted Answer

Django docs on boolean operators

Gives you:

{% if user in users %}
  If users is a QuerySet, this will appear if user is an
  instance that belongs to the QuerySet.
{% endif %}

and

{% if a == b or c == d and e %}

Be aware that and has a higher order of precedence than or, and that parentheses are not possible. If required use nested blocks.

28
7/3/2018 10:28:28 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon