开发者

django 1.3 templatestag if string contains list of strings

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜