- Author:
- zalun
- Posted:
- April 28, 2009
- Language:
- HTML/template
- Version:
- Not specified
- Score:
- 0 (after 0 ratings)
Truncates string to a given number of characters.
1 2 3 4 5 6 7 8 9 10 11 12 13 | @register.filter
def trunc( string, number, dots='...'):
"""
truncate the {string} to {number} characters
print {dots} on the end if truncated
usage: {{ "some text to be truncated"|trunc:6 }}
results: some te...
"""
if not isinstance(string, str): string = str(string)
if len(string) <= number:
return string
return string[0:number]+dots
|
More like this
- Bootstrap Accordian by Netplay4 5 years, 10 months ago
- Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
- Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
- Reusable form template with generic view by roldandvg 8 years, 11 months ago
- Pagination Django with Boostrap by guilegarcia 9 years, 1 month ago
Comments
Please login first before commenting.