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
|- backe开发者_Go百科nds/
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?
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.
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.
Make sure that backends is on the python path and has a init.py file in the folder.
精彩评论