Login

Slice filter

Author:
sneeu
Posted:
March 6, 2007
Language:
Python
Version:
Pre .96
Tags:
filter string slice simple
Score:
-1 (after 7 ratings)

Handy for things such as: {{ some_string|slice:","|join:";" }}

1
2
3
@register.filter
def slice(s, delimiter=' '):
    return s.slice(delimiter)

More like this

Comments

jcroft (on March 6, 2007):
<p>The name "slice" conflicts with the built-in "slice" filter. I'd definitely recommend anyone who use this change the name, or you could be headed for troubled.</p>

#

jacobian (on March 6, 2007):
<p>Yeah, I'm not sure this works at all... strings don't have a "slice" method, so likely this doesn't do anything except throw an error.</p>

#

whiskybar (on March 7, 2007):
<p>Did you mean split?</p>

#

sneeu (on March 14, 2007):
<p>Ah yes, sorry - it should be called split.</p>

#

Please login first before commenting.