Skip to content

Instantly share code, notes, and snippets.

@jpadilla
Created September 14, 2011 17:04
Show Gist options
  • Save jpadilla/1217108 to your computer and use it in GitHub Desktop.
Save jpadilla/1217108 to your computer and use it in GitHub Desktop.
Truncate a string after a certain number of characters
from django import template
register = template.Library()
@register.filter
# truncate after a certain number of characters
def truncatechars(value, arg):
if len(value) < arg:
return value
else:
return value[:arg] + '...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment