Happiness buildings are really the key, and you have to plan ahead. Once you start having public order problems, it's too late to be building them. But if you've built all of the public order buildings available, and have a reasonable sized garrison, a couple spies to keep out saboteurs and malcontents, and sufficient priests to keep religious problems down, then squalor shouldn't matter too much.