Saturday, March 14, 2009

Django on App Engine Gotchas

I've been trying to use Google App Engine (GAE) of late. As a Python newbie its a fairly steep learning gradient. App engine as it ships is fairly simple but missing many of the conveniences I've grown accustomed to from using other web frameworks so I thought I'd drop Django in to the mix.

Out of the box, Django is designed to work with relational databases. The GAE doesn't have a relational database, instead it has Google's clustered non-relational database BigTable. This changes a lot for Django. The models change, the forms which were based on the models change. The built-in management app which was based on the previously mentioned items has to change. So, there's a project to patch all of that and get it working again - google-app-engine-django

As I mentioned above, I'm new to Python and perhaps if I weren't many of the things I'll mention below would be no big deal. But here are the issues that I've found with using google-app-engine-django so far:

  • Check it out of subversion. I think that this project is still fairly new. At the time of writing, the latest release was r52. The latest subversion release fixed at least one bug for me that had cost several hours of my time so I highly recommend getting the latest version you can.

  • You need to install a late version of Django in the django folder under your project. I didn't feel that this was made clear in the install instructions and it wasn't until I found this that I started to make some progress.

  • Use
    python manage.py shell
    To play around and experiment with your models.

  • Set the USER_EMAIL environment variable to your email address. I noticed this when trying to instantiate a model that had a line:
    created_by = db.UserProperty(auto_current_user_add=True)

    It seems that the add_current_user_add=True requires that environment variable to be set. I haven't tried deploying the app yet but I suspect that it's not an issue when running on Google's servers because there really is a concept of a current user.

Those are the crux of what I've learned so far. Looks easy but there are lots of rocky outcrops on which to get snagged.

No comments: