samedi 6 mars 2021

Local and Global Variables in If statement (Error)

I have been having a problem with a bit of code. I have readed Python documentation about local and global variables. As I understand it, local and global scope isn't affected by if statements.

My code is the follow:

user = request.user
if user == auction.user:
    owner = True

print(owner)

Nevertheless, i have this error: UnboundLocalError: local variable 'owner' referenced before assignment.

Can you tell me what's the cause of this error? And, how can i fix it?

Thx.

Aucun commentaire:

Enregistrer un commentaire