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: Unused 'myValue ' at end of if expression
How can I do an If AND in a template??
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.
Should be something like this:
{% if myList|length and myValue == 'somestring' %}
blah blah
{% endif %}
Django docs on boolean operators
Should be something like this
- view.py
def posts_request(request):
message=ApplyPost.objects.filter( blah blah)
if message:
return render (request,'blah.html',{'message':message})
- 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
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 %}