From the Mega Flask Tutorial