UnboundLocalError: local variable 'title' referenced before assignment



  • I have a condition.

    if title in info:
    

    So elaborate:

    def post(self):
    info = self.request.body
    

    try:
    info = json.loads(info) if info is not False else False

    if info is not False:

    if title in info:
    title = info.

    Why does he have this mistake, because it's a normal condition?

    UnboundLocalError: local variable 'title' referenced before assignment



  • info - JSON object. You need to check if the object info contains the key 'title'.

    if 'title' in info:
        # do something
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2