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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -