Skip to main content
2 of 3
added 181 characters in body
Martijn Pieters
  • 1.1m
  • 326
  • 4.2k
  • 3.4k

You have a dictionary, use the dict.get() method to return a default value for missing keys:

image_file = self.request.files.get('image_path') 

Also, do not use pokemon exception handling. You really don't need to catch them all here; if a key is missing, KeyError is raised, you should catch just that one exception.

Martijn Pieters
  • 1.1m
  • 326
  • 4.2k
  • 3.4k