Django 中的电子邮件身份验证(奇怪的错误)
我已将其插入到settings.py中:
AUTHENTICATION_BACKENDS = (
'blog.auth.backends.EmailBackend',
'django.contrib.auth.backends.ModelBackend',
)
博客是一个应用程序(正确安装),auth是博客应用程序中的文件夹,backends.py是包含此方法的文件:
from django.contrib.auth.backends import ModelBackend
from django.core.validators import email_re
from django.contrib.auth.models import User
class EmailBackend(ModelBackend):
def authenticate(self, username=None, password=None):
if email_re.search(username):
try:
user = User.objects.get(email=username)
if user.check_password(password):
return user
except User.DoesNotExist:
return None
return None
我的问题是:
为什么我会收到此错误? :
ImproperlyConfigured at /signup/
Error importing authentication backend auth.backends: "No module named auth.backends"
I have inserted this in settings.py:
AUTHENTICATION_BACKENDS = (
'blog.auth.backends.EmailBackend',
'django.contrib.auth.backends.ModelBackend',
)
blog is an application ( correctly installed ), auth is a folder in blog application, backends.py is the file that contain this method:
from django.contrib.auth.backends import ModelBackend
from django.core.validators import email_re
from django.contrib.auth.models import User
class EmailBackend(ModelBackend):
def authenticate(self, username=None, password=None):
if email_re.search(username):
try:
user = User.objects.get(email=username)
if user.check_password(password):
return user
except User.DoesNotExist:
return None
return None
My question is:
Why I get this error ? :
ImproperlyConfigured at /signup/
Error importing authentication backend auth.backends: "No module named auth.backends"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此外,您可能需要清除会话“从 django_session 中删除;”。我在升级 django 版本时遇到了这个问题。
Also you may need to clear your sessions 'delete from django_session;'. I ran into that when upgrading django versions.
您应该确保所有使用的文件夹(博客和身份验证)中都有一个
__init__.py
!You should make sure to have an
__init__.py
in all of the used folders (blog and auth)!