[Django]-Subscripting Strings in django templates

7👍

You can, but the syntax is slightly different as what you’re used to. Use slice:

{{ stringVar|slice:":2" }}

This will give you the first 2 elements from the list (or the first two chars from a string).

👤jro

Leave a comment