Listing, truncate description data: truncatechars:'150' - Django - 33

When we have long text fields and we want to cut them, I think it's a good idea to limit it, so for this we can use the truncate filter for that:

<p>{{e.description | truncatechars:'150'}}</p>

Here we are going to write truncate chars and indicate the quantity here, I am going to put about four to test, no more than four characters should appear and there we have it perfect, obviously I don't want it to be only four, I am going to put about 150, I think it looks pretty good although you can customize it to your liking. The idea is that a novel, a very long text, does not appear here, but rather something considerably short for that purpose appears, but again you can customize it, at least I wanted to do the implementation there, so this was all I wanted to do.

I agree to receive announcements of interest about this Blog.

Truncate texts in Template in Django.

- Andrés Cruz

En español