Refactors render methods to extracts duplicate code

I noticed that `render` and  `render_template` were basically identical save for one line. This pull request extracts the context creation and actual rendering code into their own methods.