Saturday, July 24, 2010

Django on Google App Engine

In case that you want to run the head (latest version) of django on the google app engine this will help you. The info bellow is for a new project (in case you need information on how to make it work with an
existing project see the README file from the appengine_helper).

First you need to understand what is different between running django on your server where you have a RDBMS like mysql and the datastore that google provides. To do this look into the following link

After you are done reading do the following:
(i'm using /tmp as an example, you can change it to whatever you want)

cd /tmp/

- download the appengine_helper_for_django (if the link changed because there is a new version replace bellow the names for helper with the new names)

curl -L -o '' ''

- download  the latest version of django (you can download it or use the svn to checkout)

curl -L -o 'Django-1.2.1.tar.gz' ''

- untar the django

tar xvfz Django-1.2.1.tar.gz

- make a new temporary directory for your application

mkdir myapp_tmp

- extract the django helper 

cd myapp_tmp
unzip ../

- rename the helper

mv appengine_helper_for_django/ myapp

- copy the django framework to have it available

cp  -r ../Django-1.2.1/django  myapp

- configure the app and run the webserver

cd myapp
ls    (you should have something like this)

HANGES VERSION appengine_django urls.pyc
COPYING django
KNOWN_ISSUES __init__.pyc index.yaml settings.pyc
README app.yaml

- edit the app.yaml to reflect your application name etc.

- run the webserver to test

python runserver
(you should see the output from the app engine starting)


/Applications/ DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import md5
/Applications/ DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import sha
WARNING:root:Could not read datastore data from /var/folders/TI/TIS6v9poFPyMZ3GaFkfkjE+++TQ/-Tmp-/django_vpsup.datastore
WARNING:root:Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO:root:Checking for updates to the SDK.
INFO:root:The SDK is up to date.

that's it ! you can start using django as you normally do.

(in case you want to change the location of your myapp directory all you have to do is to move the myapp to the new destination - mv /tmp/myapp_tmp/myapp /home/myuser/applications/myapp)