My Experiments with Django… with interesting results!

So I was all ready to try out this beautiful framework called “Django”. (Funny, always reminds me of the great guitarist Django Reinhardt). And so I go to the homepage of Django and get version 0.95. I decided to test it all out on my Windows box before trying it out on good ol’ unpredictable Linux (okay,okay GNU/Linux). So far so good.

Installation went off without a hitch. The prerequisites had already been loaded (Believe me, the prerequisites list is almost as big as that for GNU/Linux software packages and almost as obscure… my eternal gratitude to the maintainers of the “Cheeseshop” who make my life easier!) and I was ready to take the plunge. I decided to start with the “Django book”. In case you haven’t already got lost in the pool of URLs already (though it couldn’t possibly ever equal that of Slashdot’s), you can get this gem of a book here. Excellent book. Take my word for it!

So I start off with the initial pages and I already like these guys! The Awesome Threesome as I would like to call them – Adrian Holovaty (loved his duel with David Heinemeier Hansson in this excellent video), Simon Willison (the soft-spoken Brit) and Jacob Kaplan-Moss (the dude who presented a Django demonstration in Google). Their sense of humor (I suspect mostly Adrian’s) is wonderfully to my liking. A bit on the sarcastic-and-yet-almost-self-flagellating-and-still-almost-playing-dumb-and-yet-profoundly-enlightening-humor-which-hits-you-after-you-have-finished-laughing type. You know what I mean? Anyway, to get back to the flesh of the discussion, there I was happily following the instructions in the Django Book and configuring here, tweaking there and everything seemed to work fine. And then I try this simple example to generate a dynamic HTML page which would purportedly return the current date and time to the user and wham!!!! The whole thing throws up an ugly page full of error messages and stack messages and what not (I thought for a moment I could even see Richard Stallman’s rotund assets there). I am distraught. I am devastated. I am ruined. Naah… I am just messing around with you. In true hacker fashion, I set about dissecting the error messages, painstakingly tracing the chain of errors back to the source. Ha ha ha… who am I kidding? In even truer hacker fashion, I went straight to the source code and tinkered around a bit. I could find the source of error to be the wrong usage of the “rindex()” method on a non-string (specifically an HttpResponse object). Nothing much I could do about that so straight to the Django users’ group where I am directed very politely to an FAQ which described my problem perfectly. So the problem was with the incompatibilities between the Django Book and the Django version!

So I shake it off, download Django 0.96 and get to work all over again. And this time the damn thing won’t even install! Bwah-ha-ha-ha-ha-ha! I wipe off my tears of
half-anguish and half-amusement and set about hacking into the code again. I find that the problem lies in the setup file. The damn thing is supposed to read the directory structure in an OS independent way and yet it does not. So I take the code and change it to hardcoded directory for my specific OS (Windows XP!!!). And voila! magic! the built-in application server for Django works starts humming and gets to work and there is this beautiful HTML generated dynamically and gosh, this really is the beginning of something beautiful! Needless to say, I have raised a “ticket” with the Django folks and thanks also to robin_percy on the Django Users’ group for saving me innumerable man seconds of time on trying to hack the Django 0.95 code. For now, everything is running chummily and hopefully I’ll have only positive stuff to post about my tryst with Django hereonin!

By the by, know why I love Python? Check this out –

set(word for word in open(“words.txt”).read().lower().split())

The single line of code above will open the file “words.txt”, read all the lines in it, change them to lower case, split them into individual words and return a set of all the unique words in the whole file! Is that cool or what?!? 🙂

My Experiments with Django… with interesting results!