register template Library register filter def undercat value len None

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
>>> register = template.Library()
>>> @register.filter
... def undercat(value, len=None):
... bits = value.split('<!--break-->')
... if bits.__len__() == 2:
... return '%s %s' % (bits[0], '')
... return value
...
>>>
>>>
>>>
>>> undercat('asdasd')
'asdasd'
>>> undercat('asdasd<!--break-->jhasgdhgfasd')
'asdasd '