1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | @register.filter
def is_in(value, arg):
'''It performs the same action as Python in statement.
It returns True if value is in arg, False if not or any error occur.
For example:
{{ 'abc'|is_in:'www.abc.com'}} -> 'abc' in 'www.abc.com'
x = 5
l = [3,4,5,6]
{{ x|is_in:l} -> x in l
'''
try:
return value in arg
except:
return False
|
More like this
- Run and cache only one instance of a heavy request by farnsworth 2 years, 10 months ago
- joinstrings filter by Tomek 2 years, 7 months ago
- Dynamic query builder with AND/OR by bobwaycott 3 years, 9 months ago
- template tag for highlighting currently active page by adunar 4 years, 7 months ago
- Wiki-like markup for sub templates by luckystarr 5 years, 9 months ago
Comments