The code is in place... Point your browser to http://localhost:8080/ and let's see what we've got!
Oh, we've got an error. Since we're in development mode, CherryPy gives us the whole traceback, which is very convenient. The traceback is telling us that we got an SQLObjectNotFound exception. D'oh! We forgot to put a page in the database! Let's do that using a special version of the Python interactive shell:
tg-admin shell Page(pagename="FrontPage", data="Welcome to my front page")
That's all there is to it. We just created a new page in the database.
Reload your browser window, and you'll see our beautiful page.
One of the hallmarks of wikis is that you can edit the page just by clicking "Edit This Page". That and the wikispam that follows... hopefully, spammers won't find your Wiki 20 before we're done with it!
Let's start by creating a template for editing. Let's start with a copy of "page.kid":
cd wiki20/templates cp page.kid edit.kid cd ../..
In edit.kid, change the text at the top from "Viewing" to "Editing" and replace the <div> for the data with:
We need something to use this template now. We'll add an "edit" method to our controller:
This method is very similar to our index method. The main difference is that the index method renders the wiki content as HTML, and this one returns the straight text.
We need a way to get to our edit method, so we'll edit page.kid to add this to the bottom:
That should do it! Reload the page in your browser, and you'll see the edit link. Follow that link, and you'll get a page that lets you edit. Don't click that save button, yet! We still need to write that method.
The form we made in the last section had an action of "save". So, we need to make a method called save in our controller. Here's what it looks like:
We also need to add cherrypy to our imports so that we can do the redirect:
import cherrypy
Interesting things to note about this:
Go ahead and try it out! You can make changes and save the page we were editing. Pretty wiki-like, no?