vendredi 28 février 2020

Why am I getting syntax error in nested if..else statement in Django views

I believe in Python we can do the following:

if expression1:
   statement(s)
   if expression2:
      statement(s)
   elif expression3:
      statement(s)
   elif expression4:
      statement(s)
   else:
      statement(s)
else:
   statement(s)

I am trying to do something like this in Django views:

if qs1.count() > 100:
    # do something
elif qs1.count() - qs2(count) < 12:
    # do something else
elif qs3.count() > qs2.count():
    if qs1.count() == qs3.count():        # Error here <<
         # do whatever
else:
    # forget it

I am getting SyntaxError: invalid syntax at the code line shown.

What am I doing wrong? How do I improve the statement flow so as not to encounter an error.

Aucun commentaire:

Enregistrer un commentaire