开发者

django 1.3 templatestag if string contains list of strings

开发者 https://www.devze.com 2023-04-05 07:32 出处:网络
How can I check if a string is one of a list of values (\'image_1\', \'image_2\'..etc) How can check if a string equal to one开发者_开发知识库 of the values in the list? In python, an equavilant wo

How can I check if a string is one of a list of values

('image_1', 'image_2'..etc)

How can check if a string equal to one开发者_开发知识库 of the values in the list? In python, an equavilant would be

if 'mystring' in ('yes' ,'no', 'mystring'):
  return True

how can i do the above using django templatetags?


Django templates come with thein operator as well.

{% if some_string in some_list %}
    Do something
{% endif %}

This was first introduced in django 1.2 as one of the operators supported by the "smart" if tag.

0

精彩评论

暂无评论...
验证码 换一张
取 消