Apache 无法识别 Django 自定义身份验证后端
我正在尝试使用 mod_python 将 Django 应用程序部署到基于 Apache2 的服务器。我已经正确设置了处理程序并进行了配置以使 mod_python 适用于我的项目。我的项目实现了一个自定义身份验证后端来将我的用户连接到 Twitter,并且我的后端实现位于:
myproject
|- backends/
目录。一切似乎都工作正常,我的页面加载并且我可以正确进行读/写操作。但每当我尝试使用 Twitter 帐户登录时,应用程序都会引发异常,告诉我:
导入身份验证后端 backends.twitteroauth 时出错:“没有名为 backends.twitteroauth 的模块”
在我的 settings.py 中,我将后端注册为
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'myproject.backends.twitteroauth.TwitterBackend',
)
什么是问题?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除数据库解决了我的问题。据我猜测,如果用户登录,他相应的登录后端将作为会话变量保存在数据库中。我的 settings.py 文件是
在我进行更正之前。更改 settings.py 并重新启动应用程序是不够的。您还必须从数据库中删除与会话相关的记录。
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
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.
问题是 python 找不到模块
twitteroauth
。TwitterBackend
所在的文件的名称是什么?还要确保backends
中有一个__init__.py
文件将其标记为包。编辑:
如果您运行 shell
并尝试将其导入那里,会发生什么?
由于其他一切都工作正常,我猜
myproject
位于您的 python 路径中。The problem is that python cannot find the module
twitteroauth
. What is the name of the fileTwitterBackend
is in? Also make sure that there is a__init__.py
file inbackends
to mark it as a package.edit:
What happens if you run the shell
and try to import it there?
As anything else works fine, I guess
myproject
is in your python path.确保 backends 位于 python 路径上,并且文件夹中有 init.py 文件。
Make sure that backends is on the python path and has a init.py file in the folder.