Sunday, September 25th, 2005

TurboGears: Python in the battle

Category: Screencast, Toolkit

Python has always had quality web solutions. Django was an early Rails competitor, and now Kevin Dangoor has given us TurboGears.

To check it out you should see the 20 minute video where Kevin builds a Wiki application.

You will see TurboGears in action, including the parts and pieces that it uses:

  • MochiKit is a clean and powerful JavaScript library
  • Kid is a designer- and programmer-friendly template system
  • CherryPy makes doing web input/output as easy as writing a Python function!
  • SQLObject lets you access your database as you would normal Python classes, without obscuring the database itself.

TurboGears is very Ajax friendly

The demo shows you how pages can return JSON data automagically (via ?turbogearsfmt=json, instead of /js for Atlas), and that you have a high level abstraction to be able to use this data in a simple Ajaxian manner.

The example has an onclick event on an anchor tag (to activate the function: requestPageList), with an empty div to fill next to it, and the following JavaScript:

<script type="text/javascript">
function requestPageList() {
  d = loadJSONDoc("/pagelist?turbogearsfmt=json");
  d.addCallback(showPageList);
}

function showPageList(result) {
  pages = result["pages"];
  currentpagelist = UL(null, map(row_display, pages));
  replaceChildNodes("pagelist", currentpagelist);
}

function row_display(pagename) {
  return LI(null, A({"href": "/?pagename=" + pagename}, pagename));
}
</script>

Which returns the JSON:

{“pages”:[“FrontPage”,”TurboGears”],”turbegearsflash”:null}

Resources

Nice work Kevin!

turbogears-movie.png

Posted by Dion Almaer at 10:37 am
Comment here

+++--
3.2 rating from 13 votes

Comments Here »

Comments feed

Leave a comment

You must be logged in to post a comment.