I want to do something like:
{% if ("view_video" in video_perms) OR purchase_override %}
Is that possible?
DjangoTemplates engines accept the following OPTIONS : 'autoescape' : a boolean that controls whether HTML autoescaping is enabled. It defaults to True . Only set it to False if you're rendering non-HTML templates!
Django Templates. Django provides a convenient way to generate dynamic HTML pages by using its template system. A template consists of static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted.
Variable names consist of any combination of alphanumeric characters and the underscore ( "_" ) but may not start with an underscore, and may not be a number.
You cannot use python code in django template. This is by design, Django's idea of template is to isolate the presentation logic from the programming code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With