Getting Started with Django on Google AppEngine
Django is a pretty interesting looking web application framework available for python, and a lot of the inspiration for Google AppEngine (in terms of the python implementation at least) have apparently come out of use of Django. Presently AppEngine has out of the box support for Django 0.96 but if you want to get up and running with the latest stable version of Django you have to jump through a few hoops.
The following article gets you well on your way:
http://code.google.com/appengine/articles/django.html
One problem, however, is that there have been some changes in django that mean the code they provide to call initialize django from your main.py script doesn’t work. Change your main.py script it to what is displayed below, however, and it all works fine:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import logging, os, sys # Google App Engine imports. from google.appengine.ext.webapp import util # Remove the standard version of Django. for k in [k for k in sys.modules if k.startswith('django')]: del sys.modules[k] # Force sys.path to have our own directory first, in case we want to import # from it. sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) # Must set this env var *before* importing any part of Django os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' import django.core.handlers.wsgi import django.core.signals import django.db import django.dispatch.dispatcher def log_exception(*args, **kwds): logging.exception('Exception in request:') # create a new signal object sig = django.dispatch.Signal() # Log errors. sig.connect(log_exception, django.core.signals.got_request_exception) # Unregister the rollback event handler. sig.disconnect(django.db._rollback_on_exception, django.core.signals.got_request_exception) def main(): # Create a Django application for WSGI. application = django.core.handlers.wsgi.WSGIHandler() # Run the WSGI CGI handler with that application. util.run_wsgi_app(application) if __name__ == '__main__': main() |
The key being that django.dispatch.dispatcher no longer works, and you need to create a django.dispatch.Signal instance and use that in place of the dispatcher.connect and dispatcher.disconnect function calls.
Update:
Thanks to @joerussbowman for the heads up on app-engine-patch which is a quick and easy way to get up and running with django on appengine. Definitely recommend checking it out.

