Log in

No account? Create an account
Django 1.0.2 and Google App Engine - Nick [entries|archive|friends|userinfo]

[ website | gagravarr.org ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Django 1.0.2 and Google App Engine [Apr. 8th, 2009|02:46 pm]
It looks like my next project at work will involve a Google App Engine hosted Facebook application.

As I'm a big fan of Django, I figured I'd try to use quite a bit of django in the app. App Engine does ship with Django, but an older version, and it's a little fiddly to tie in all the way down.

Luckily, there's a handy bit of glue code to tie it all together, the cunningly titled Google App Engine Django. After a little bit of prodding, and using zip files to get around file limits, I have managed to get it playing nicely together. The steps roughly are:

  • Make sure you have a new enough copy of the app engine python SDK (1.2.0 or later)
  • Symlink the sdk to .google_appengine in the root of your application
  • Create a /lib/ directory in your app to hold things
  • Download Django 1.0.2, and zip the django directory to /lib/django.zip (zip -r ~/code/myproject/lib/django.zip django/)
  • Do a svn checkout of google-app-engine-django (http://google-app-engine-django.googlecode.com/svn/trunk/)
  • Zip the appengine_django directory to /lib/appengine_django.zip (zip -r ~/code/myproject/lib/appengine_django.zip appengine_django/)
  • Grab app.yaml, main.py, manage.py and urls.py from google-app-engine-django, and put them in the root of your application
  • Update app.yaml with your app's name
  • In main.py, after "import logging" but before the first of the appengine_django imports, add in:
    # Put our zips onto the path before loading anything else
    sys.path.insert(0, 'lib/appengine_django.zip')
    sys.path.insert(1, 'lib/django.zip')

  • (More info on why you want to import from zips, and how available here)
  • Do the same sort of thing to manage.py, by adding before the first import
    # Load in appengine_django and django from the packaged zips
    import sys
    sys.path.insert(0, 'lib/appengine_django.zip')
    sys.path.insert(1, 'lib/django.zip')

  • Start dev_appserver.py on your application
  • Begin coding your almost-django app engine application!

From: ext_181963
2009-04-18 05:44 pm (UTC)

You need to check out App-engine patch

It enables a bunch more for Django check my blog for some info but really check out the project site.. http://tombrander.wordpress.com
(Reply) (Thread)
[User Picture]From: barnacle
2009-06-06 03:56 pm (UTC)

Minor corrections!

Great recipe. It got me a good 90% of the way there. You might want to add the following:

  • lib/ needs a __init__.py file
  • manage.py needs an import sys statement
  • The zips need to be built in the directory containing the top-level directory to be zipped up, or the system path won't work. That means descending into the appengine_django directory, much as you zip up the django subdirectory beforehand.

These are broadly obvious (the third maybe with your Java .jar experience!) but worth mentioning.

(Reply) (Thread)
[User Picture]From: barnacle
2009-06-06 04:08 pm (UTC)

Re: Minor corrections!

Also, I'm having some trouble nesting the zipfiles in the lib/ subdirectory: they want to have the GAE symlink in the same subdirectory, which then looks there for a settings.py file, which then.... Eventually, my whole app was living in lib/. Any thoughts?
(Reply) (Parent) (Thread)