Opened 11 years ago

Closed 11 years ago

#6468 closed (duplicate)

nested ForNode iteration over non-sequence attributed to parent

Reported by: Joshua Tacoma <joshua@…> Owned by: nobody
Component: Template system Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When a ForNode contains a ForNode over a non-sequence, the resulting TemplateSyntaxError refers incorrectly to the first ForNode.source.

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
from django.template import Context, Template, TemplateSyntaxError
source = '''{% for item1 in list1 %}
{% for item2 in list2 %}
{% endfor %}
{% endfor %}'''
    Template(source).render(Context(dict(list1=[1], list2=2)))
except TemplateSyntaxError, e:
    print source[e.source[1][0] : e.source[1][1]]
    print e.exc_info[1]

Ought to produce this output:

{% for item2 in list2 %}
iteration over non-sequence

But instead produces this:

{% for item1 in list1 %}
iteration over non-sequence

...which is quite misleading. May be related to #4565?

I'll be studying the flow of template/ and template/ but this is my first effort to fix a bug in Django so it's more of a learning exercise. If you already know how to solve this, well, don't wait for me!

Change History (2)

comment:1 Changed 11 years ago by Jim <jim-django@…>

related to #5831 ?

comment:2 in reply to:  1 Changed 11 years ago by Gary Wilson

Resolution: duplicate
Status: newclosed

Replying to Jim <>:

related to #5831 ?

Yes, I'd say it's a dup.

Note: See TracTickets for help on using tickets.
Back to Top