About ANDs and ORs in Django Templates
ANDs precede ORs in the conditions of most programming languages. So these following two lines are equivalent in Python:
condition1 and condition2 or condition3 and condition4
(condition1 and condition2) or (condition3 and condition4)
Django template language doesn't have a concept of parentheses in conditions, so the above condition would look like this:
{% if condition1 and condition2 or condition3 and condition4 %}
...
{% endif %}
To have ORs executed before ANDs in Django templates, use nesting:
{% if condition1 or condition2 %}
{% if condition3 or condition4 %}
...
{% endif %}
{% endif %}
Tips and Tricks Programming Django 5.x Django 4.2 Django 3.2 Python 3
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django GDPR Cookie Consent app
For Django websites that use cookies.