Django 'if and' pattern

I want to do the following in my django html page:

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

but I get the error: Not using 'myValue' at the end of the if statement

How can I do if AND in a template?

+5
source share
4 answers

Try the following:

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

See the django documentation on using boolean-operators and complex-expressions in django templates.

+15
source

There should be something like this:

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

, if ifequal :

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

Django docs

-

  • 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 %}

{% if a == b or c == d and e %}

, , , .

0

All Articles