
Hey, where's the page?
============================================

What if a Wiki page doesn't exist? We'll take a simple approach: if the page
doesn't exist, you get an edit page to use to create it.

In the ``default`` method, we'll check to see if the page exists. If it doesn't,
we'll redirect to a new ``notfound`` method. We'll add this method after the
``index`` method and before the ``edit`` method. Here are the changes we make to
the controller:

.. literalinclude:: ../../project_code/wiki_root/snapshots/7/wiki20/controllers/root.py
   :linenos:

**19:**  The ``default`` code changes illustrate the "better to beg
forgiveness than ask permission" pattern which is favored by most
Pythonistas -- we first try to get the page and then deal with the
exception by redirecting to a method that will make a new page.

**38:**  We're also leaking a bit of our model into our controller.
For a larger project, we might create a facade in the model, but here
we'll favor simplicity. Notice that we can use the ``redirect()`` to
pass parameters into the destination method.

**45:** the first two lines of the ``notfound`` method add a row to
the page table. From there, the path is exactly the same it would be
for our ``edit`` method.

With these changes in place, we have a fully functional wiki. Give it a try!
You should be able to create new pages now.


