The 20 Minute Wiki

by Kevin Dangoor

There is a printable version of this document.

This is the text version of the "20 Minute Wiki" video (40MB QuickTime). (See video help for more information about viewing the videos.)

To go through this tutorial, you'll want:

  1. docutils 0.3.9 or later, which is used for formatting. You could get away with not having docutils, but it's not as much fun. easy_install docutils should get you what you need.
  2. A web browser
  3. Your favorite editor
  4. Two command line windows (you only need one, but two is nicer.)
  5. A database. If you don't have one, your best bet is sqlite 3.2+ with pysqlite 2.0+.

This tutorial doesn't cover Python at all. Check the docs section for more coverage of Python.

The Quickstart

TurboGears has a command line tool with a few features that will be touched upon in this tutorial. The first is "quickstart", which will get us up and running quickly.

tg-admin quickstart

You'll be prompted for the name of the project (this is the pretty name that human beings would appreciate), and the name of the package (this is the less-pretty name that Python will like). For this tutorial, we'll be using these values:

Enter project name: Wiki 20
Enter package name [wiki20]: wiki20
Do you need Identity (usernames/passwords) in this project? [no] no

This creates a few files in a directory tree just below your current directory. Let's go in there and you can take a look around.

cd Wiki-20

Now Serving: Number 1

You may have spotted a file called start-wiki20.py. This is the startup script for the built-in web server. Let's run it!

python start-wiki20.py

Point your browser at http://localhost:8080/, and you'll see a nice little welcome page with the current time. (If you're on a Mac and have Bonjour bookmarks turned on in Safari, you'll see your new server show up there!)

That was easy!

Easy indeed. And, if you take a look at the code that the quickstart created, you'll see that there isn't much involved in getting up and running. Two interesting things to look at:

Let's make a wiki!

If you're not familiar with a Wiki, you might want to check out the Wikipedia entry. The whole idea is that it's an easily-editable web content system that makes it trivial to link to pages and create new pages.

TurboGears follows the Model-View-Controller paradigm, as do most web frameworks these days. Kid templates are your view, your CherryPy classes are your controllers and basically any object can be your model. In practice, since we're in a database-driven world, your model objects will be SQLObjects.

Since this is all about pages, why don't we go ahead and set up a place to store our pages. TurboGears quickstart gave us a "model.py" module with enough in it to start creating model classes. Here's our Page class:

My own personal preference is to work with objects (and not SQL) as much as possible. SQLObject does support creating objects based on the database definition. I prefer to work the other way and create the database definition based on the objects.

For the pagename, we specified alternateID=True, which will guarantee that the column is unique and allow us to easily do searches on pagename. Some databases require the length to be specified on columns you want indexed, we'll just use the arbitrary length of 30 here.

Continue on to page 2

Download

TurboGears 0.9a9

August 17, 2006

Features: Widgets, ModelDesigner, Identity framework, FastData, and much more

Download now button Upgrade instructions button

Download development version from SVN

Get involved

Order the DVD and more!

The TurboGears Ultimate DVD is now shipping! More than 5 hours of video!
We also have the marble rolling mini-framework you've been looking for.

Hosting Options

TurboGears can be hosted in many places, but we've got 4 of the best choices picked out. Super simple TurboGears use from WebFaction starting at $11.50 a month or, if you need more control, dedicated servers from ServerPronto starting at just $29.95 a month. Check it out
last updated: Aug 09, 2006
Comment on this page