Matt's Blog: while { coding }
    Back to Matt's Homepage   |   Hire Matt

Django – You know, Boba’s Dad

For the past six months I’ve been pretty heavy into a Python web framework called Django. For the most part I’ve been quite happy with it, especially since for a few months prior I had been playing with PHP and that wasn’t making me too happy. Still, there have been a lot of things to get used to:

First off, it’s Python. Don’t get me wrong, Python is a fine language, but it is new to me. I assumed incorrectly that being comfortable with the language would be enough to make development a breeze. It was not. Python is an exceedingly obvious language, at least if you take a little time to learn it. Much more so that previous languages which felt as powerful such as C++ or Perl. Still, coding in Python has it’s quirks. There’s the whole indentation-as-syntax thing, which works much better than I thought it might, but still doesn’t read as well as I’d hoped. But, for the most part the indentation scheme avoids Brace Wars, which I find myself getting irrationally religious about. (Let’s not go there.)

Nits about Python:

You can’t mix indentation types. For instance, you can use tabs or spaces, but not both. Which makes sense on an individual line, but gets annoying if you cut and paste some code from somewhere. I have found 4-space indents work better for me than tabs, but sometimes I cut and paste code when I’m learning something new, and about 70% of code I find seems to use tabs. That’s when Python has a hissy. I don’t understand it, but I trust there’s a good reason it can’t do it on a line-by-line basis. That would certainly make my life easier.

Another thing I kept running into was with creating libraries. I’d code up a class, thow it into a folder in the PYTHONPATH and try to import from it. And what would happen over and over until I learned better? My module was never found. Reason? No magical “__init__.py” file in my folder. Yes, just the presence of the file means “hey, there’s some code here to import”. Not the way I’d have done it, but then again I don’t know the whole story.

Overall my Python nits are minimal. I don’t get the exhilaration I used to get from making something with amazing performance in C++, and I don’t get the  smile that comes across my face when I code in Perl. But I do get things done. I guess it’s a lot like VB in that way. Except not stupid. :)

My problems with Django are still evolving, but so far my biggest problem with Django is configuration. OMG it is a fucking pain in the ass.

Now, I should qualify that: If you already have a current Python, you can install and run Django pretty easily. You just download it, install it, then use the django-admin.py script to create your first app. Once your app is created you can use a mini Python appserver while you develop. You can make changes to the live app and they will get swept up into the current instance of the appserver. It’s similar to the webrick server you would use with Rails. And since sqlite ships with later Python releases, you can have a working, database-backed webapp up and running in about 5 minutes. Of course it won’t do much (aside from the wonderful built-in admin system), but still, to get started that fast is great.

Of course, no one is going to put an app into production with the little webserver that Django gives you. For production you need to tie in with a real webserver. Traditionally that means Apache, which is what I use. There are other high performance web servers that people are using (apparently with great success) with Django, but I’m old school. At least for the time being. Besides, Apache is widely available and supported on a lot of servers, so it makes for an easy target.

Or so you’d think, anyway. Getting a full stack of Apache, mod_python, MySQL, and Django turns out to be the biggest obstacle to working with Django “for reals”. I’m probably spoiled by years of working with stacks that have more integration like .NET, or just more raw ammo, like Perl/CPAN.

I believe I can honestly claim that out of the past 3 months, I’ve spent approximately 1.5 to 2 months dealing with Django configuration. Part of that is my fault. For one thing, I want to have a proper deployment waterfall: development box, staging box, client review, then client’s production.  Which means trying to set up the same damned thing over and over again. Which shouldn’t be a problem, except that I’m developing on my Intel Macbook, staging on my G4 Mac Mini, pushing to review on a Django-friendly Ubuntu hosting provider, and then finally pushing out to a Fedora production box. If this was Perl I probably wouldn’t give a shit. But it ain’t.

The weak points turned out to be mod_python (the Python interpreter which you embed into Apache) and MySQLdb (the MySQL access library for Python). The mod_python install actually hasn’t been so bad. I did have trouble at one point getting mod_python to use the correct Python version. (I cheated and renamed the one that was in the system PATH first. Lame but it worked.) Getting MySQLdb was much more of a pain in the ass. Apparently very few people use MySQL from Python (Postgres seems to be far, far more popular), because there’s basically one dude who maintains the MySQLdb library. That’s a recipe for a lot of blind corners and situations where things don’t work so well. I spent an inordinate amount of time getting MySQLdb working, and I think I still don’t have it working right on my development box.

Oh, that’s right. Did I mention that? I can’t run the full Django stack on my Intel Macbook. Partially because of the MySQLdb crap (I clearly have Intel, it clearly thinks I have PPC. Wtf?), but also partly because of one other library, Python Imaging Library. That fucker will NOT build on my Macbook. Since the main client app I’m working on uses that (sort of… I think the feature it was included for never gets used), I can’t run Django for client development on my primary machine.

All of which means I’m shelling over to my Mac Mini (which hangs daily, btw. Fun.) and developing there (In pico. Yay.), or sometimes I just give up altogether and code on the review box.

Now, this all probably sounds kind of negative. And it is, but only about short-term things. When everything is actually up and running, developing with Django is fast and pretty enjoyable. But getting to that point costs a small portion of your soul.

Worse, I think my Joel score just went down.