Yax
Yax

Reputation: 2189

Django Invalid filter: 'truncatechars_html'

I am trying to display content that has HTML tagS in it and also wants to truncate it if the character is more than 1000 but it is affecting my CSS layout if article is truncated at a tag that is opened and not closed before the truncation point.

Code:

{% if article.content_length > 1000 %}
    <p>
        {{article.content|truncatechars_html:1000|safe|linebreaks}}
    </p>
    <a href="#">See more...</a>
{% else %}
    <p>
        {{article.content|safe|linebreaks}}
    </p>
{% endif %}                 

Though {{article.content|truncatechars:1000|safe|linebreaks}} works fine but when I change it to {{article.content|truncatechars_html:1000|safe|linebreaks}} I get the error below:

TemplateSyntaxError at /mysite/article/mysite/

Invalid filter: 'truncatechars_html'.

Upvotes: 0

Views: 501

Answers (1)

Sebastian
Sebastian

Reputation: 2897

Make sure you are using Django 1.7 or later. The truncatechars_html filter is not available in earlier versions.

Upvotes: 2

Related Questions