[Solved]-Grouping Conditions in Django template if statement

12👍

Since the order of evaluation is the following:

  • or
  • and
  • not

you can omit the parenthesis:

{% if not owner.home_number or owner.work_number or owner.mobile_number %}
    No contact number available
{% endif %}

Or, just FYI, you can also reverse the check:

{% if owner.home_number or owner.work_number or owner.mobile_number %}
{% else %}
    No contact number available
{% endif %}
👤alecxe

0👍

( not a valid syntax here.

If you want to convert: if is_admin and (requested or exempted)

you could use something like:

{% if is_admin and requested or is_admin and exempted %}

Leave a comment