To get the length of a string in a template with Django, a solution is to use the filter length:
{{ value|length }}
Example:
{{ title|slice:":35" }} {% if title|length > 35 %}...{% endif %}
returns with title = "Mon titre est tres tres tres longgggg"
Mon titre est tres tres tres longgg ...
References
Links | Site |
---|---|
filter length | django doc |
Django-templates: Why doesn't {% if “string”|length > 10 %} work at all? | stackoverflow |