views:

169

answers:

3

I'm trying to deploy my Django application to an Apache2 based server with mod_python. I've set the handlers right and made the configuration to make mod_python work with my project. My project implements a custom auth backend to connect my users to twitter, and my backend implementation is on:

myproject
|- backends/

directory.Everything seems to be working fine, my pages load and I can make read/write operations properly. But whenever I try to login with my Twitter account, application fires an exception telling me:

Error importing authentication backend backends.twitteroauth: "No module named backends.twitteroauth"

In my settings.py, I'm registering my backend as

AUTHENTICATION_BACKENDS = (
   'django.contrib.auth.backends.ModelBackend',
   'myproject.backends.twitteroauth.TwitterBackend',
)

What is the problem?

+2  A: 

The problem is that python cannot find the module twitteroauth. What is the name of the file TwitterBackend is in? Also make sure that there is a __init__.py file in backends to mark it as a package.

edit:

What happens if you run the shell

python manage.py shell

and try to import it there?

from myproject.backends.twitteroauth import TwitterBackend

As anything else works fine, I guess myproject is in your python path.

Felix Kling
TwitterBackend is a class and the file is twitteroauth. I have __init__.py inside the directory.
Burcu Dogan
`init.py` or `__init__.py`?
Felix Kling
+1  A: 

Make sure that backends is on the python path and has a init.py file in the folder.

silent1mezzo
A: 

Removing database solved my problem. As far as I can guess, if a user is logged, his corresponding login backend is kept as a session variable on the database. My settings.py file was

AUTHENTICATION_BACKENDS = (
   'django.contrib.auth.backends.ModelBackend',
   'backends.twitteroauth.TwitterBackend',
)

before I made the correction. Changing settings.py and restarting the application was simply not enough. You have to remove session related records from db too.

Burcu Dogan