Archive for January, 2009

DjangoUnicodeDecodeError gotcha!

Wednesday, January 14th, 2009

I’ve been working with international websites lately. Got this error on the Django admin pages, but no other pages on the website:

DjangoUnicodeDecodeError: Caught an exception while rendering: ‘ascii’ codec can’t decode byte … in position:6: ordinal not in range (128) ….

Went through the following steps:

1. Is my input in utf-8? Yes.
2. Is the database properly storing the right encoding? Yes.
3. Is Django pulling the data out in utf-8? Yes.

Strange, this means the data is in the right encoding, but when it is trying to display on the admin page the encoding is getting lost or coerced in to the wrong thing.

After a cup of coffee, I remembered the admin pages sometimes use the unicode() function if you don’t explicitly tell them what to display. Looked into the model code and gasped in horror:


def __unicode__(self):
return str(self.title)+u":"

Flip the str to unicode and admin pages work again.

Gotta add that to the code review list.

I can’t wait for AppEngine to gain ground

Thursday, January 8th, 2009

Over the past eight months or so I’ve worked on a variety of web applications. A bunch of them have been using Django, and I’m extremely happy with Django. It’s definitely the quickest, easiest way to get an application out the door.

I’ve been splitting the apps between webfaction, amazon’s EC2, and Google App Engine. By far, the easiest to work with is AppEngine. I can safely delegate almost all of the operations aspect to Google. Backups are a bit hard, but once you resign yourself to scripting it all out, everything just works.

Webfaction comes in a close second – it’s main problem is that it costs money. You can pretty much just code and deploy with it. With AppEngine you are forced to do everything with Django – so using wordpress or some other app is not an option. Webfaction gives you pretty much what you need.

EC2 is a whole other beast altogether. If you want almost complete control, go with EC2. The biggest stumbling block for me is relearning all the system operations stuff I haven’t had to do since my grad school days putting together linux and freebsd clusters.

What’s my point? Well this:

AppEngine – you concentrate on building your app. Operations is largely left to Google. Note, you should definitely use app-engine-patch, it makes Django 1.0 very easy to use on AppEngine.

Webfaction – you work on your app most of the time, you have to dust off some apache configuration skills every once in a while when you need to integrate some other app in the mix.

Amazon EC2 – Work on your app mostly, but you better be prepared to learn about:
nginx, haxproxy for load balancing
apache configuration and security in detail
database configuration, security, and backups in detail
EC2 tools for starting/stopping/replicating server instances

My AppEngine apps are small right now, but they require the least amount of work by far. I wish I could do everything on AppEngine.