Django Template: {% If 5 In ['4', '3', '5'] %} Doesn't Work
form.tickets.value has the values ['29', '4', '7'] ticket_id has values such as 5, 3, 7 etc. Now I want to print YES if 7 exist in the list. But it always says 'No'. Anyone can tel
Solution 1:
In Python, the type of the variable matters. You are comparing an integer to a list of strings. Since the types differ, the values will never be equal (even though they "look" the same).
You could either convert your lists to lists of integers instead of strings, or convert the integer you are comparing to a string. Here's an example of the latter, using one of Django's built-in template filters:
{% if ticket_id|stringformat:"s"in form.tickets.value %}
Post a Comment for "Django Template: {% If 5 In ['4', '3', '5'] %} Doesn't Work"