Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 'if and' template

Tags:

python

django

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??

like image 281
user1646528 Avatar asked Feb 19 '13 12:02

user1646528


People also ask

How do you do if statements in Django?

How to use if statement in Django template. In a Django template, you have to close the if template tag. You can write the condition in an if template tag. Inside the block, you can write the statements or the HTML code that you want to render if the condition returns a True value.

What does {{ name }} this mean in Django templates?

What does {{ name }} this mean in Django Templates? {{ name }} will be the output. It will be displayed as name in HTML. The name will be replaced with values of Python variable.

What is DTL in Django?

Django Template Language (DTL) is the primary way to generate output from a Django application. You can include DTL tags inside any HTML webpage. The basic DTL tag you can include in an HTML webpage is: 1. {% Tag %}


2 Answers

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.

like image 199
arulmr Avatar answered Oct 17 '22 15:10

arulmr


Should be something like this:

{% if myList|length and myValue == 'somestring' %}
   blah blah
{% endif %}
like image 33
kmerenkov Avatar answered Oct 17 '22 15:10

kmerenkov