更新时间:2022-05-07 22:30:52
如果您需要使用
try:
object = DemoModel.objects.get(id=8)
#use object here
catch DoesNotExist:
#catch stuff here
如果不需要,请使用exis ts()。
If you don't need to, just use exists().
if DemoModel.objects.filter(id=8).exists():
#do stuff here