Created
September 14, 2011 17:04
-
-
Save jpadilla/1217108 to your computer and use it in GitHub Desktop.
Truncate a string after a certain number of characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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