Thursday, September 3, 2009

Pyjamas vs. Django

My hobby project is to create a website for my girlfriend's business. I don't want to reveal too much but the website will need to display the usual corporate information like services available, contact details, previous client testimonials etc. There will also need to be a section where potential clients can view available timeslots and apply for a booking with a consultant at any of those timeslots. This will be the hard part.

I don't want a username login sorta thing as that's too complicated. I think it will be enough to show an Outlook-style date/time calendar showing what times are available and allowing the user to select from the remaining timeslots, providing their name and contact details so a consultant can call them back and arrange the booking. Once the booking is arranged, the consultant will have to update the system so that the timeslot is shown as unavailable.

As these is a certain amount of dynamic data involved in the site, I'll use Python and a web framework to make serialisation to a database easier. After shopping around I have found many people happy with Django. The needs of this website are very modest so when people complain about Django not holding up under heavy load those arguments don't really apply here. I'm all about building this site rapidly and robustly.

The other side of the fence is Pyjamas which is a Python port of Google Web Toolkit (GWT) which allows you to write code in Python (originally in Java) which will be automagically converted to HTML and JavaScript when you compile using the GWT/Pyjamas toolset.

I have decided that Django is the tool for the job as I have no need to AJAX functionality, just basic client/server communication with a little pizazz on the client end to make it look nice.

(edit) In further reading it appears these are pretty different tools- Pyjamas is a front end development and Django is a total solution. All the better for me.

First step: Django Tutorial
I installed Django 1.0.2 from the Ubuntu repo and some of the other Django related bits and pieces that sounded interesting. I'll stick with SQLite for now until I need a proper RDBMS. I see that Django is dependent on JQuery which is good- I was intending to use that to flash up the site.

I have set up a Pydev project and tried to run the command to create a Django site in that location but it can't find the file First I had to find out how to search the filesystem for a file (find -iname "filename") then I had to find out how to add that location to the system path.

Now the file is on the system path but when I cd to the project folder and run the command I get access denied. Next I sudo the command and it says it can't find the command. WTF?

So I find the file and edit it and the first line (which I believe indicates which binary should execute it) says "#!/usr/bin/env python". I had a look and /usr/bin/env doesn't exist! No idea why the default installation of Django would reference Python from a location that doesn't exist. Maybe I'm supposed to make a symlink there that points to my Python interpreter of choice? I'll learn how to create symlinks then try it out.

I don't have to create a symlink, it turns out that /usr/bin/env is some sort of environment variable list allowing me to change the location of the Python executable easily. It's a level of indirection so that the location of Python doesn't have to be hardcoded into .py files.

After much toiling around I have found that I can get it to work by running "/usr/bin/python createsite xxx". Not sure why I have to manually invoke Python, I would have thought it would automatically be associated with .py files? Anyway, that was needlessly difficult but I finally have a site up. I'll continue the Django tutorial and get started on the real work.

No comments:

Post a Comment