Subscripting Strings in django templates

Is it possible to subscript strings in django templates ?

What i mean is doing

print "hello"[:3]
=> hel

in django templates.

Writing {{ stringVar[:10] }} throws

TemplateSyntaxError: Could not parse the remainder: '[:10]'  from 'stringVar[:10]'


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).

Need Your Help

Adjust width and padding of data tables

javascript jquery css datatables

I have around 6 tables those padding or width is different.When I was not using data tables, their padding and width were set inline. Now the inline doesn't work.

Page jerks on changing id in url?

javascript jquery html css

I have page with 10 blocks each taking the height of the window. I'm trying to change the url by adding the blocks id to the url on scrolling down the page like The url updates fine but