how we can implement this coniditon in django template

How i can implement this condition in django template with multiple and or statement in if?

 {% if ((email_setting.twitter_link is not None and email_setting.twitter_link != '') 
 or (email_setting.instagram_link is not None and email_setting.instagram_link != '') 
 or (email_setting.fb_link is not None and email_setting.fb_link!= '') ) %}
  Here my body
 {% endif %}

this give me an error

TemplateSyntaxError at /settings/emailView
Could not parse the remainder: '((email_setting.twitter_link' from '((email_setting.twitter_link'

Answers: 2

Answered by Willem Van Onsem, Dec. 3, 2021, 2:11 p.m.

You can expresss this as:

{% if email_setting.twitter_link or email_setting.instagram_link or email_setting.fb_link %}
{% endif %}

Here we check the truthiness of the twitter_link and other settings. The truthiness of None and the empty string are False whereas for a non-empty string, it is True.

Answered by Talha Yousaf, Dec. 3, 2021, 2:14 p.m.

i was searching for this exact thing and i found out this answer on stack overflow.


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