Email authentication in Django ( strange error )
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 b开发者_JAVA技巧log 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"
Also you may need to clear your sessions 'delete from django_session;'. I ran into that when upgrading django versions.
You should make sure to have an __init__.py
in all of the used folders (blog and auth)!
精彩评论