我已在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"
答案 0 :(得分:5)
此外,您可能需要清除会话'从django_session删除;'。我在升级django版本时遇到了这个问题。
答案 1 :(得分:3)
您应确保在所有已使用的文件夹(博客和身份验证)中都有__init__.py
!