Roughly following the Flask tutorial