我在python中有以下代码:
def update(request, id):
success = 0
try:
product = Mattress.objects.get(id=id)
success = 1
except Mattress.DoesNotExist:
pass
if success == 1:
return render_to_response("success.html")
else:
return render_to_response('failure.html')
此代码是检查“成功”布尔值的有效方法吗?如果代码通过了try语句,“success”会变为1还是保持为0?