Mimsy Were the Borogoves

Hacks: Articles about programming in Python, Perl, PHP, and whatever else I happen to feel like hacking at.

Quick & dirty Snakelets “blog”

Jerry Stratton, April 7, 2007

I wrote this quick and dirty blog to work on some techniques discussed at an ETech tutorial a week ago Monday. This is the first time I’ve taken a tutorial at ETech; normally I find the conference sessions much more compelling and don’t take the extra time away from work to do the tutorials. This year, however, there was a fascinating-sounding tutorial on creating addictive user experiences. And since tutorials come in twos, I also chose the interesting-sounding “Web Heresies”.

The heresy was treating HTML as code rather than design, jettisoning templates and instead creating very simple HTML appropriate for CSS. The corollary to the heresy was that the objects themselves would handle all of their HTML and form processing.

The user experience tutorial ended up cancelled. On coming to the Heresy tutorial, I discovered that I was unprepared. The description indicated I needed a favorite programming language; what I actually needed was:

  1. An object-oriented language
  2. A web application server
  3. Something else I don’t remember

Right. So, for object-oriented language I could use PHP, Perl, or Python, or fake through Ruby which I’ve only used once, and for a few minutes (trying and failing to get Ruby on Rails set up). The instructor was going to use Ruby-like pseudocode, but that didn’t seem like it was going to work well enough for me to learn Ruby in a few minutes.

The only web application server I’ve used (other than the abortive attempt to use Rails) is Django. This inclined me towards using Python as the OO language of choice, but installing Django, quickly, for non-templated, non-databased web development seemed both overkill and difficult. I don’t know how to set up a model without a database backend; I’d probably have to do all of the programming in the view.

So I did a quick web search for python web applications, and came upon Snakelets. It promised to be a quick install with each webapp being nothing more than a Python package. That turned into the most fascinating aspect of the tutorial for me.

Which was surprising, because the documentation for Snakelets (like much in the Python world) can be very cryptic.

The test

On Monday evening, I started thinking about what I could do with Snakelets, and what I could do to try out the heretical techniques we discussed in the tutorial.

What about a really quick and dirty blog for really quick and dirty blogging?

  1. Posts are created by requesting the URL for the post.
  2. Posts can’t be edited once they’re created.
  3. Posts contain only a few fields: a title and a description.
  4. There are no templates. Each object—posts, post lists, pages—know how to create their own HTML.
  5. All layout is handled by CSS.

The only interface for entering information about the blog is the post. The name of the blog, and the blurb about the blog? That’s the post for index.sn, the Snakelets index page name.

Set up Snakelets

  1. Download the Snakelets server. As I write this, the server is currently at 1.44.
  2. gunzip Snakelets-1.44.tar.gz
  3. tar -xvf Snakelets-1.44.tar
  4. cd Snakelets-1.44
  5. python serv.py

That should start the server. Read the text that comes up when you run it, and look for something like “Processing vhost 'George.local' root...”. That’s the hostname Snakelets picked up. You can browse your Snakelets install by going to “http://hostname:9080/”. In my case, “http://george.local:9080/”.

You can change the port by editing serv.py and changing the line that says “HTTPD_PORT = 9080”. Also, make sure that your firewall allows you to access port 9080 (or whatever port you choose). And if you need to change the hostname that Snakelets uses (for example, to localhost) you can change “bindname=None” in serv.py to “bindname=hostname”. You’ll need to restart the server (CTRL-C and then “python serv.py” again) for those changes to take effect.

Once you have the server running to your liking, you can also go to http://hostname:9080/manage/ to see the management screens for Snakelets. The default admin username and password is “test” and “test”. It’s in “webapps/manage/__init__.py”. You’ll want to change that immediately. Change the line: