ryan
ryan

Reputation: 2331

Having trouble importing middleware classes in App Engine / Django

Trying to get facebook connect to work on app engine, and so I'm following these instructions:

http://www.slideshare.net/mrtrosen/lab305-django-facebook-connect-integration-example

One of the steps requires me to add to my middleware_classes, and so I've added the following to settings.py (copied from slide 18 in the presentation above):

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'facebook.djangofb.FacebookMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'facebookconnect.middleware.FacebookConnectMiddleware',
    )

However, when I view my app locally (which was working before adding this to settings.py), I get the following error:

ImproperlyConfigured: Error importing middleware facebook.djangofb: "No module named facebook.djangofb"

However, when I go to the terminal, I am able to run python and when I type "import facebook.djangofb" I do not get any error.

FYI, the facebook package is in /Library/Python/2.6/site-packages.

Any ideas as to why this might be happening? I've been stuck on this for a while so any help would be greatly appreciated.

Thanks!

Upvotes: 0

Views: 990

Answers (2)

jldupont
jldupont

Reputation: 96806

All modules must reside under your app's folder hierarchy. Be sure to also add the required paths to sys.path in your app request handlers.

The sys.path should be updated to something along the lines of:

root = os.path.split(__file__)[0]
sys.path.insert(0, os.path.join(root, 'folder1'))
sys.path.insert(0, os.path.join(root, 'folder2'))

where folderX is contained under the app folder. This "path adjustment" should be done in each "request entry point script" in the application.

Upvotes: 0

John Stallings
John Stallings

Reputation: 581

Google App Engine uses python 2.5 runtime I believe, thus you will have either move the facebook directory into the project as suggested above or move it over to the 2.5 site-packages if you have python 2.5 installed as well.

Upvotes: 1

Related Questions