views:

376

answers:

3

So I'm trying to use the django 1.1 template engine with the google app engine web app framework, from here. This is on Ubuntu Jaunty, I've made sure that the PYTHONPATH contains the location of Django-1.1.1 yet I'm getting this 'ImportError: No module named django' error when it tries to execute the use_library() line below. Again, could somebody help me? I'm stumped.

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
from google.appengine.dist import use_library
use_library('django', '1.1')
+1  A: 

Did you get an answer to this? Having SAME issue.

A: 

@stallarida - The problem is that .96 is shipped as default with the SDK. What I did in the end, which is a dirty hack but works, is to update the version of django in the appengine directory to 1.1. Worked fine, needed a bit of tweaking between dev and production. Specifically I had to comment out use_library('django', '1.1') when running locally but include it when uploading my app.

I'm sure there's a better solution and I'll work it out when my linux experience improves.

Phil
+3  A: 

Came up with the following solution:

Get django 1.1 and put it under your project root.

Add an empty file "non_gae_indicator" to your project root folder.

Add django and non_gae_indicator to your app.yaml skip_files element:

skip_files:
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?index\.yaml
- ^(.*/)?index\.yml
- ^(.*/)?#.*#
- ^(.*/)?.*~
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*/RCS/.*
- ^(.*/)?\..*
- ^(.*/)?.*\.bak$
- ^django
- ^non_gae_indicator

Now we have a way to tell whether we are running under the GAE-sdk or live - since non_gae_indicator won't be available when we are live.

So in main.py you can do:

if not os.path.exists(os.path.abspath(os.path.dirname(__file__)) + '/non_gae_indicator'):
    # GAE
    from google.appengine.dist import use_library
    use_library('django', '1.1')
else:
    # Not GAE - Add our django package to the path
    sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)) + '/django')

You should run your local SDK server with the --allow_skipped_files flag (or else the skipped files will appear to not be exist when checking them - the server console gives a warning about it).

TheOsp