Unpacking a Tuple in a Django Template

Posted by: scoopseven 13 years ago

You've passed in a tuple to your template and now you're trying to access the separate indexes/items in a loop. Here's the tuple: REGIONS = ( (1, 'East'), (2, 'West'), (3, 'South') ) And this is how you'd unpack/decode it in your Django template: for id, region in REGIONS:     print 'id: %s, region: %s' %(id, region) If only everything was that easy.

Currently unrated


Recent Tweets

Recent Posts

Archive

2013
2012
2011
2010
2009
2008
2007
2006

Categories

Authors

Feeds

RSS / Atom