diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2010-09-07 20:30:46 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2010-09-07 20:30:46 +0000 |
| commit | 0b37d56481d453e79b322fef28313c83bb806561 (patch) | |
| tree | f6840ef8b8ca29ad40db9de919f4a0eb7bfa8a2d /django | |
| parent | 4f4e20be3333a656996c027a52a4a06d4a2a2480 (diff) | |
Fixed #13475 - for tag raises an exception when trying to unpack a non-iterable item
Thanks to SmileyChris for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13690 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/template/defaulttags.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 318ae5ffd2..d629a690c5 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -157,15 +157,22 @@ class ForNode(Node): loop_dict['first'] = (i == 0) loop_dict['last'] = (i == len_values - 1) + pop_context = False if unpack: # If there are multiple loop variables, unpack the item into # them. - context.update(dict(zip(self.loopvars, item))) + try: + unpacked_vars = dict(zip(self.loopvars, item)) + except TypeError: + pass + else: + pop_context = True + context.update(unpacked_vars) else: context[self.loopvars[0]] = item for node in self.nodelist_loop: nodelist.append(node.render(context)) - if unpack: + if pop_context: # The loop variables were pushed on to the context so pop them # off again. This is necessary because the tag lets the length # of loopvars differ to the length of each set of items and we |
