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. Django Settings Assignment Expressions aka Walrus Operator example by webology 2 weeks, 2 days ago
  2. codigo alto nivel by MrRocklion 2 months, 1 week ago
  3. Load template from specific app by Krzysiek555 3 months ago
  4. PostgreSQL JSON subqueries by dolamroth 3 months ago
  5. "Magic Link" Management Command by webology 8 months, 1 week 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.