I have cleared everything out of the house and didn't spend time in the supermarket near the cakes and sweet stuff.
It sounds obvious and almost silly, but you're right. Just not buying the wrong stuff in the first place makes it much easier not to eat it
Mind you, to my credit, I've had a bag of chocolates in my cupboard for a month or so now. I'm waiting for a time to treat myself