Reputation: 177
On the Django docs for built in tags and filters they give a filter to truncate words but not characters (letters/numbers/spaces, etc). Is there such a thing available?
Upvotes: 6
Views: 6725
Reputation: 2749
As of Django 1.4, truncatechars
is now a built-in filter in the release.
https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#truncatechars
Upvotes: 7
Reputation: 555
It was a feature request for 4 years but finally landed in trunk, as far as I understand https://code.djangoproject.com/ticket/5025 - so we’ve to wait for the next release or use trunk.
Upvotes: 0
Reputation: 887
You can use the slice notation: {{ a_string_variable|slice:":5" }}
This would give you the first 5 characters in the string.
Upvotes: 8
Reputation: 2457
I used this before and works fine :
http://djangosnippets.org/snippets/194/
Upvotes: 0