python - variable 'error' referenced before assignmentRequest -


in django application, have checks in form return error = "something".
thing that error not defined unless there error.

mycharacters = character.objects.filter(username_id=request.user.id)  if(mycharacters.count() >= 5):     error = true if not error:     #save db 

the problem if there no error, error variable not exist.

i have thought possibility in order avoid error, be:

error = none #checks here if error == none:     #save db 

but not sure whether best approach.

is there way if error var not exist: in python?

you can following:

error = mycharacters.count() >= 5 if not error:     ... 

update

error = mycharacters.count() >= 5 if error:     to_json = {"incorrect":"excedeed maximum"} else:     # save db 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -