[Django]-Limiting the content of TextField in django templates

9đź‘Ť

âś…

truncatechars¶

Truncates a string if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence (”…”).

Argument: Number of characters to truncate to

For example:

{{ value|truncatechars:9 }}
If value is “Joel is a slug”, the output will be “Joel i…”.

docs

👤Dmitry Yudin

0đź‘Ť

You can use Built-in Template tag "truncatewords", like this below:

{{ post.post_body | truncatewords:50 }}

This will show the first 50 words of your post.

Here is the Documentation

👤Sumon Ahmed

Leave a comment