Delete the last 3 letters of a string in a Django template [: -3]

I do the following:

{% for wrapping in wrappings %} //array of strings <input type="radio" value="{{ wrapping[:-3] }}" etc 

I want to print the entire string in a wrapper minus the last 3 letters, but I get a:

TemplateSyntaxError: Could not parse the remainder: '[:-3]' from 'wrapping[:-3] .

Any idea what's wrong / how to do this, please? Thanks,

+6
source share
3 answers

You can use the slice filter:

 {{ wrapping|slice:":-3" }} 
+16
source

For this you need a slice filter.

+1
source

{{ variable|slice:":-3" }} will do this.

0
source

All Articles