views:

333

answers:

2

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!

A: 

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.

jldupont
Are you saying I should move the facebook directory from /Library/Python/2.6/site-packages and move it to the same directory where settings.py is? I just tried that as well, restarted my app and am still getting the same error. Apologies if I misunderstood your suggestion.
ryan
Your appengine `app` exists under folder `f`: all the required modules must live under `f`.
jldupont
does my answer help you?
jldupont
Maybe I'm still misunderstanding you. Here's what I did: I have a folder called MyApp that contains app.yaml, index.yaml, main.py, settings.py as well as some other directories. I've moved the facebook directory into MyApp but that still doesn't work. I also tried moving it up a level (so it's in the same directory as MyApp) and that doesn't work either.
ryan
did you follow my advice regarding `sys.path` ?
jldupont
Yes, I tried sys.path.append('/Users/ryan/Documents/MyApp') in both main.py and settings.py but that didn't work either.
ryan
no: see my update.
jldupont
Thanks for all your help. Still hitting issues. Tried your suggestion of root = os.path.split(__file__)[0]sys.path.insert(0, os.path.join(root, 'facebook'))but I get the same error. I then wanted to confirm that the path was actually getting put in sys.path, so I then added raise Exception(sys.path) and while I would have expected to see the item I just inserted (i.e. ending in /facebook) as the first item in the list, it was not in the list at all. Again, I'm new to this so I'm sorry if I'm missing something obvious or just being otherwise dense.
ryan
are the modules for python2.5? AppEngine only supports 2.5 at the moment.
jldupont
is my answer satisfactory?
jldupont
A: 

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.

John Stallings