django在读取数据库时未筛选到符合条件的记录会报错
时间:2017-08-17 18:59:54
收藏:0
阅读:279
(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."
原文:http://www.cnblogs.com/stuqx/p/7383753.html
评论(0)