willcritchlow
willcritchlow

Reputation: 741

Is boolean logic possible in django templates?

I want to do something like:

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

Is that possible?

Upvotes: 23

Views: 28104

Answers (1)

Spacedman
Spacedman

Reputation: 94182

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.

Upvotes: 41

Related Questions