Reading the source code of the "slice" filter in Django it looks to me
like it should work on strings as well as lists. If you only need to
truncate and discard the extra characters, that would be the way to go.
--~--~-~--~~~---~--~~
You received this message beca
Siah wrote:
>Please let me know if this feature is available, or else I'll find out
>how to implement it as a filter myself.
>
>
A filter would look simple:
def truncate(value,arg):
return value[0:arg]
However it won't work for international characters. This will:
from djang
emm.. But wait a sec! How do I call a python function from django
template. I don't think it is allowed, meaning that I'd still have to
write a filter using textwrap:
>>> wrap('siasookhteh', 5)
['siaso', 'okhte', 'h']
Sia -
--~--~-~--~~~---~--~~
You received thi
Thanks David. I did feel there should be a way to do this since it
seems common enough.
I'll read up on textwrap now,
Regards,
Sia
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to th
Hi Sia. I don't believe you need a filter. Just import textwrap module
and do what you want. See textwrap module on python.org in the docs for
more.
Regards,
David
Siah wrote:
> Hi,
>
> I noticed there is no filter to truncate a string to a given number of
> characters as apposed to just word
Hi,
I noticed there is no filter to truncate a string to a given number of
characters as apposed to just words. It can be useful. For instance I
am trying to show contact list that includes email addresses, and given
that some people have bizarrely long emails, I'd like to limit it to
some value.
6 matches
Mail list logo