Adjust factory method to follow Flask extension guidelines

Based on 85cdf6bbb968debfa622ccb819ee9849b5a94e88 and
21c4ca7968c5da2c8d9fdb7f13774ec50fe062a5, authored by Matt Wright
<matt@nobien.net> @mattupstate