Login

Slice filter

Author:
sneeu
Posted:
March 6, 2007
Language:
Python
Version:
Pre .96
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

  1. Template tag - list punctuation for a list of items by shapiromatron 4 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 4 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 11 months, 2 weeks ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year ago
  5. Help text hyperlinks by sa2812 1 year ago

Comments

jcroft (on March 6, 2007):

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.

#

jacobian (on March 6, 2007):

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.

#

whiskybar (on March 7, 2007):

Did you mean split?

#

sneeu (on March 14, 2007):

Ah yes, sorry - it should be called split.

#

Please login first before commenting.