@register.filter('slice', is_safe=True)
def slice_filter(value, arg):
 try:
  bits = []
  for x in arg.split(':'):
   if (len(x) == 0):
    bits.append(None)
   else:
    bits.append(int(x))
  return value[slice(*bits)]
 except (ValueError, TypeError):
  return value

@ register . filter ( 'slice' , is_safe = True ) def slice_filter ( value , arg ) : try : bits = [ ] for x in arg . split ( ':' ) : if ( len ( x ) == 0 ) : bits . append ( None ) else : bits . append ( int ( x ) ) return value [ slice ( * bits ) ] except ( ValueError , TypeError ) : return value
returns a slice of the list .