Refactoring to render templates with flask