django在读取数据库时未筛选到符合条件的记录会报错
(1)报错情况如下:
DoesNotExist: Publisher matching query does not exist.
(2)处理方法:
try:
p = Publisher.objects.get(name='Apress')
except Publisher.DoesNotExist:
print "Apress isn't in the database yet."
else:
print "Apress is in the database."
p = Publisher.objects.get(name='Apress')
except Publisher.DoesNotExist:
print "Apress isn't in the database yet."
else:
print "Apress is in the database."