Updated add_page code for both view and template. Checks that the category exists before adding the page.