[Fixed]-Django 'if and' template

39👍

Try this:

{% if myList|length and myValue == 'somestring' %}
    blah blah
{% endif %}

Refer django documentation about use of boolean-operators and complex-expressions in django templates.

👤arulmr

18👍

Should be something like this:

{% if myList|length and myValue == 'somestring' %}
   blah blah
{% endif %}

2👍

Django docs on boolean operators

Should be something like this

  1. view.py
def posts_request(request):  
    message=ApplyPost.objects.filter( blah blah)
    if message:
       return render (request,'blah.html',{'message':message})
  1. blah.html
{% if message %}
     {% for post in message %}
          {% if post.provider %}
              ....
          {% endif %}
          {% if post.accept == True and post.provider %}
              ...
              ...
          {% endif %}
          ....You can add multiple if,elif, with Operators ....
    {% endfor %}
{% if message %}

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

0👍

I think you might have to separate the if and the ifequal in two statements:

{% if myList|length  %}
     {% ifequal myValue 'somestring' %}
          blah blah
     {% endifequal %}
{% endif %}

Leave a comment