2

i am using nested for loop in django template to print data which i get from the data base

            {% if objectives %}
            {% for obj in objectives %}
            {% for sobj in sobjective %}
            {% if sobj.id==obj.id %} yes {% endif %}

all the open tags are closed

but its raising an error as i mentioned above

TemplateSyntaxError at /objectives
Could not parse the remainder: '==obj.id' from 'sobj.id==obj.id'
  • Add spaces around `==`. – Willem Van Onsem Mar 28 '20 at 20:24
  • Have you looked at the solutions mentioned [in this question](https://stackoverflow.com/questions/19428572/django-templatesyntaxerror-could-not-parse-the-remainder)? It's possible that the error is not in the code snippet you provided. – rassar Mar 28 '20 at 20:34

1 Answers1

2

The Django template language requires spaces around the == operator, so you should implement this as:

{% if sobj.id == obj.id %} yes {% endif %}

In Python x==y would be valid, but Django's template language has specific tokens and grammar.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
  • thank you very much for your help i have another issue its about scope i am using a variable in try: tage but when i create a dictionary outside of "try" django rais an error that local variable referenced before assignment i try to change the scope by writing global but it does not fixed my error by the way . you have any idea about that? – Muhammad Arsalan Toor Mar 28 '20 at 21:20