python - how to handle try for possible object not existing in django -
i have object may or may not exist. due fact have wrapped statement in try / except block.
try: generic_type = contenttype.objects.get_for_model(myentity) my_object = myobject.objects.filter(content_type__pk=generic_type.id, object_id=myentity.id)[0] except:
the reason ask because have nothing put in except condition in situation, django/python requires it.
is proper way handle situation? if is, should put after except?
you can use pass
statement anywhere statement required when want nothing, although should specify actual exception catch.
except whateverexceptiongetsraised: pass
Comments
Post a Comment