views:

253

answers:

4

I'm trying to install app engine with django 1.1 on windows.

When launching the app engine I'm getting the following error: http://slexy.org/view/s21oLrbkHh

The steps I do are: 1.) Create new app via launcher 2.) Copy my code (Which is empty django project)

My main.py code is attached below. I'm falling on line: "import django.db" which I can do successfully from cmd.

Do you have an idea?

main.py:

\# main.py

import os, sys
os.environ["DJANGO\_SETTINGS\_MODULE"] = "taskhood.settings"
sys.path.append("/home/brox/tmp/mashname")

\# Google App Engine imports.

from google.appengine.ext.webapp import util

\# Django version 

from google.appengine.dist import use_library
use_library('django', '1.1')

\# 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
import django.dispatch.dispatcher

def log_exception(*args, **kwds):
   logging.exception('Exception in request:')

\# 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()
A: 

Django 1.1 is not the default version on App Engine, use 0.96 in stead or specify that you want to use 1.1. See this article on goodle code.

For that matter, the models need to be adapted as App Engine does not have a regular (sql) database. That's also described on the given link.

extraneon
Not true: see http://code.google.com/appengine/docs/python/tools/libraries.html#Django
Daniel Roseman
That's funny, I use Django 1.1 on App Engine minus Django's Model.
Thierry Lam
You're right. It *is* supported but you have to specify it. I'll change the answer.
extraneon
A: 

Why do you need django.db? How do you propose to use it? My guess is Django is searching for sqlite and it is not able to find it? Maybe if you install it the error would go.

dhaval
+2  A: 

As others have noted, you can't use Django's ORM on AppEngine. However it's obvious that you are following some instructions to import django.db in order to disconnect some signals. The error message shows you the problem: the sqlite3 library is not installed on your system.

Usually this comes along with Python versions 2.5 onwards, so you should have it as part of your 2.6 installation, but perhaps you have a minimal install for some reason. Try installing one of the full Python versions, from python.org or ActiveState, or you could try just installing the pysqlite2 library.

Daniel Roseman
You can import db, but you have to adapt the models. I think google might have done some magic on the db module.
extraneon
A: 

Make sure your DB configuration in your settings.py is blank:

DATABASE_ENGINE = ''           
DATABASE_NAME = ''             
DATABASE_USER = ''             
DATABASE_PASSWORD = ''         
DATABASE_HOST = ''             
DATABASE_PORT = ''

Along with the following:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
)

INSTALLED_APPS = (
    'django.contrib.contenttypes',
    'django.contrib.sites',
)

The above is the bare minimum to run Django on GAE minus its admin.

I'm using the following main.py in two different Django on GAE projects and they work fine:

import logging, os, sys
from google.appengine.dist import use_library
use_library('django', '1.1')

# Must set this env var *before* importing any part of Django
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

# 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__)))

import django.core.handlers.wsgi
import django.db


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()
Thierry Lam