I am using Django and I am wondering how I can accomplish this. It works fine in python in Linux but the HTML Templating language keeps saying it cannot parse the array.
{% if myvalue in ["128","256","512","768","1024","1536","2048","3072","5120","10240"] %}
<p> Hello World
{% endif %}
It says it cannot parse the remainder and then it displays the list.
To check if the list contains an element in Python, use the “in” operator. The “in” operator checks if the list contains a specific item or not. It can also check if the element exists on the list or not using the list.
The most straightforward way to get the number of elements in a list is to use the Python built-in function len() . As the name function suggests, len() returns the length of the list, regardless of the types of elements in it.
Python Find String in List using count() We can also use count() function to get the number of occurrences of a string in the list. If its output is 0, then it means that string is not present in the list. l1 = ['A', 'B', 'C', 'D', 'A', 'A', 'C'] s = 'A' count = l1.
You can't create arbitrary lists in the Django templating system. You need to pass the created list via your view. See This question for a detailed discussion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With