Making a Flickr Killer With TurboGears – Part 1: Introduction To TurboGears

One month ago, I gave an introductory speech about TurboGears at the Israeli Pythoneers Meeting. The discussion consisted of two parts. The first part introduced TurboGears, and the second part included live coding of a Flickr clone.


I hereby give the lecture again, in a written format. These are the original slides used in the lecture. Click on a slide to enlarge it.

Because it was only the second time I had attended one of these meetings, I briefly introduced myself. The two slides above show photos that were taken in my home town, Adi, which is a small town in Northern Israel. In the right photo, you can see my cat Uzi watching the cows in our backyard. If you have taken part in the Python Challenge, you might have already met Uzi.

TurboGears is a framework that enables the rapid development of Web applications in Python. But what is a Web application? Great question!

Wikipedia provides this explanation:

In software engineering, a Web application or webapp is an application that is accessed with a Web browser over a network such as the Internet or an intranet.
Web applications are popular due to the ubiquity of the browser as a client, sometimes called a thin client. The ability to update and maintain Web applications without distributing and installing software on potentially thousands of client computers is a key reason for their popularity. Web applications are used to implement Webmail, online retail sales, online auctions, wikis, discussion boards, Weblogs, MMORPGs, and many other functions.

What makes TurboGears stand out from the crowd is its unique philosophy of reusing. Instead of developing its own Web server, HTML-templating language and database-to-object relational mapper, it integrates existing mature and best-of-breed components. The main actors are CherryPy, which makes adding a page as easy as writing a method; Kid, which is a designer-friendly XHTML-templating language; and SQLObject, which allows you to use an SQL database without writing a single line of SQL. MochiKit is a pill library that eases your pains while coding in Javascript…

Why should you choose TurboGears as your Web-application development framework for your next project? Well, the short answer is that PHP is the devil – it tempts you to mix HTML, logic, and database queries into the same piece of code. Rails, as great as it may be, is written in Ruby, and we like Python better. For Django, I borrowed (err, stole) Adrian Holovaty’s port of Mark Pilgrim’s piece:

I was walking across a bridge one day, and I saw a man standing on the edge, about to jump off. So I ran over and said, “Stop! Don’t do it!”
“I can’t help it,” he cried. “I’ve lost my will to live.”
“What do you do for a living?” I asked.
He said, “I work with computers.”
“Me too!” I said. “What do you do with computers?”
He said, “I’m a Web developer.”
“Me too!” I said. “Design, client-side programming or server-side programming?”
He said, “Server-side programming.”
“Me too!” I said. “Do you use dynamically typed languages or statically typed languages?”
He said, “Dynamically typed languages.”
“Me too!” I said. “Do you use a Web framework, or do you roll things on your own?”
He said, “I use a Web framework.”
“Me too!” I said. “TurboGears or Django?”
He said, “Django.”
“Die, heretic scum!” I shouted, and I pushed him over the edge.

The moral of the story is that TurboGears and Django have much more in common than they have in the way of differences. It has been said that Django is like a Macintosh—it simply works—while TurboGears is more like Unix—its power comes from its being made of many smaller building blocks, each one of them designed to do one thing well.

TurboGears and Django try to solve different types of problems. Django was born in a publishers’ newsroom environment, where Web applications needed to be launched within hours. By its very nature, Django is geared toward the development of content-oriented Web sites. TurboGears, on the other hand, evolved while Kevin Dangoor was developing Zesty News, a news-reader application. As a result, it is more suitable for Web applications (see earlier definition).

Having said that, I found it very easy to develop content-oriented Web sites in TurboGears. Currently, TurboGears’ CRUD features and administration panel are somewhat lacking in comparison to Django’s. As such you have to manually code these aspects of your application if you want a non-tech author to be able to fill your project’s database with content or change various aspects of the Web site.

TurboGears goes a long way in encouraging you to design your application in the so-called MVC paradigm. MVC stands for Model, Viewer, and Controller. The model consists of the classes that represent the information on which the application operates. That information is usually stored in an SQL database. The view is composed of the HTML page templates that are used to render the model. The controller responds to user input (HTTP requests) by operating on the model and returning a view for subsequent interaction.

In a nutshell, MVC is all about separating metadata, logic, and presentation.

The above is an example of how you would model a user with SQLObject. It has first_name and last_name fields as well as a date-time field, which represents the time at which the user was last logged in to the system.

The above class definition can automatically generate the SQL table creation statement:

The “Person” class gives you a very comfortable interface with the database objects:

In the next installment, I will show you how easy it is to create a Flickr killer application with TurboGears in 37 minutes.

Make sure you won’t miss it by subscribing to the RSS feed.

This entry was posted in python, turbogears. Bookmark the permalink.

7 Responses to Making a Flickr Killer With TurboGears – Part 1: Introduction To TurboGears

  1. Pingback: links for 2007-02-09 at Blue Sky On Mars

  2. Arui says:

    Hi,friend
    I have translated this to Chinese,and post here:
    http://hi.baidu.com/aruizen/blog/item/0d656531897f7019ebc4afb6.html
    wish you don’t mind…..

  3. Nadav Samet says:

    Arui, thanks for the translation! See you around, and do not forget to translate the next installment when it is out :)

  4. Pingback: Making a Flickr Killer With TurboGears - Part 2: A Flickr Clone in 37 Minutes Flat · Nadav Samet's Blog

  5. Pingback: Screenshot l10n · Nadav Samet's Blog

  6. celebrities says:

    Excellent way of explaining, and good post to take information about my presentation topic, which i
    am going to present in institution of higher education.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>