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]'

Answers


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

Replace text with textbox contains this text

javascript html

I have a html document that contains some text, assume there is one word in each line in the document, I want to replace each word with a textbox that contains this word. Is there any easy way to d...

CreateSQLQuery works but QueryOver doesn't with NHibernate

c# mysql nhibernate model-view-controller

So I'm trying to execute a basic select query from a table to return the rows. Right now I have an object representing the data in the table and is mapped in the hbm.xml file. As far as I know, the

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.