19👍
As Mihai Zamfir commented it should work as expected. As Django documentation mentions:
Use of both and and or clauses within the same tag is allowed, with and having higher precedence than or e.g.:
{% if athlete_list and coach_list or cheerleader_list %}
will be interpreted like:
if (athlete_list and coach_list) or cheerleader_list
https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#boolean-operators
10👍
you could do the check in your view and pass a flag to the context.
show_html = user.is_admin or (something.enable_thing and user.can_do_the_thing)
context['show_html'] = show_html
Then in your template you could check the flag
{% if show_html %}
- [Django]-Capture parameters in django-rest-framework
- [Django]-How to create virtual env with python3
- [Django]-FileUploadParser doesn't get the file name
0👍
If you have the case like you said: A or (B and C)
, then Sven’s answer would work appropriately because the and
would automatically have higher precedence according to the documentation.
However, if you wish to do something like (A or B) and C
, then you could instead create and use custom template filters.
NOTE: Filters can only take at most two arguments, so they will only be useful if say, for example, you are comparing multiple attributes from 1 or 2 objects.
- [Django]-Django 1.8: Create initial migrations for existing schema
- [Django]-Can Django automatically create a related one-to-one model?
- [Django]-Running Scrapy spiders in a Celery task