is_in

 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

  1. HTML/JS template filter to show localized dates/times by mback2k 5 years ago
  2. youtubize template tag by TheJester 6 years, 11 months ago
  3. Django using admin horizontal filter in forms by crodjer 2 years, 10 months ago
  4. Filtering foreignkey fields in django admin by forgems 4 years, 10 months ago
  5. Filter that adds a period at the end of a string by Ztyx 1 year, 3 months ago

Comments

(Forgotten your password?)