Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Value in List

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.

like image 384
TheMonkeyMan Avatar asked Jan 03 '12 14:01

TheMonkeyMan


People also ask

How do you see if a value is in a list Python?

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.

How do you find the number in a list Python?

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.

How do you check if string is in a list Python?

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.


1 Answers

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.

like image 182
jeffknupp Avatar answered Oct 20 '22 02:10

jeffknupp