Slice - built-in filter

3 views
Skip to first unread message

PythonistL

unread,
Mar 21, 2006, 5:24:46 AM3/21/06
to Django users
I use SLICE filter. I t works ok, but when I try e.g.

{{ some_list|slice:":2" }}

where some_list is
some_list=[1,2,3,4]

I will get [1, 2].

Is it possible, via templates, to remove brackets?
Thanks
L.

Ivan Sagalaev

unread,
Mar 21, 2006, 5:39:14 AM3/21/06
to django...@googlegroups.com
PythonistL wrote:

Yes. After "slice" you get back a Python list which is converted to
string to appear on a page. Here you get brakets from default
representation of a list in Python. You can convert a list to a string
with "join" specifying what will be between items:

{{ some_list|slice:":2"|join:", " }}

PythonistL

unread,
Mar 21, 2006, 5:58:32 AM3/21/06
to Django users
Ivan,Thanks a lot
It really works!
L.

Reply all
Reply to author
Forward
0 new messages