How do you catch this exception?

前端 未结 6 1413
孤独总比滥情好
孤独总比滥情好 2020-12-23 15:28

This code is in django/db/models/fields.py It creates/defines an exception?

class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjec         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 16:07

    To catch this exception in general, you can do

    from django.core.exceptions import ObjectDoesNotExist
    
    try:
        # Your code here
    except ObjectDoesNotExist:
        # Handle exception
    

提交回复
热议问题