Skip to content

Instantly share code, notes, and snippets.

@philippkeller
Created December 27, 2012 12:28
Show Gist options
  • Save philippkeller/4388001 to your computer and use it in GitHub Desktop.
Save philippkeller/4388001 to your computer and use it in GitHub Desktop.
Minimum setup for getting Django 1.3 to work in Google App Engine. Do this in this order: 1. add .bash_profile lines 2. django-admin.py startproject mysite # generates mysite directory) 3. in GoogleAppEngineLauncher: create project within the mysite directory you just created (=> generates main.py and app.yaml, etc.) 4. alter main.py and app.yam…
export GAE="/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine"
export PYTHONPATH="$PYTHONPATH:$GAE:$GAE/lib/django_1_3"
export PATH=${PATH}:$GAE/lib/django_1_3/django/bin/
application: appproject
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: main.py
import os
import sys
import logging
# Google App Hosting imports.
from google.appengine.ext.webapp import util
from google.appengine.dist import use_library
os.environ["DJANGO_SETTINGS_MODULE"] = "mysite.settings"
use_library('django', '1.3')
# Enable info logging by the app (this is separate from appserver's
# logging).
logging.getLogger().setLevel(logging.DEBUG)
def log_exception(*args, **kwds):
logging.exception('Exception in request:')
# Force sys.path to have our own directory first, so we can import from it.
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
# Force Django to reload its settings.
from django.conf import settings
settings._target = None
import django.core.handlers.wsgi
import django.core.signals
import django.db
# Log errors.
django.dispatch.Signal.connect(
django.core.signals.got_request_exception, log_exception)
# Unregister the rollback event handler.
django.dispatch.Signal.disconnect(
django.core.signals.got_request_exception,
django.db._rollback_on_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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment