There is a truncate filter, it's called 'slice':
http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#slice

To show the first 10 chars do:
{{ mystring|silce:":10" }}

There's also truncatewords to make sure you always get whole words:
http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#truncatewords

Hope that helps,
Ryan

On Dec 30, 1:15 pm, Nic  Pottier <nicpott...@gmail.com> wrote:
> New to Django, but certainly not web development.  After being
> pleasantly surprised with a lot of the available Django filters I was
> rather surprised not to see a string truncation filter included.
>
> A little googling shows I'm not the only one, there are tons of people
> writing their own filters to accomplish this, and sure enough a nice
> looking patch submitted two (TWO!) years ago to add a |truncate.
>
> I'd be curious to hear what the reason for not accepting this patch
> is.  String truncation is a pretty common task, and having it built in
> seems like a no-brainer.
>
> For your reference, here's the ticket and patch:
> <http://code.djangoproject.com/ticket/5025>
>
> Thanks,
>
> -Nic

--

You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.


Reply via email to