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]'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can, but the syntax is slightly different as what you’re used to. Use slice:
This will give you the first 2 elements from the list (or the first two chars from a string).