Django email authentication (weird error)

I pasted this into settings.py:

AUTHENTICATION_BACKENDS = (
    'blog.auth.backends.EmailBackend',
    'django.contrib.auth.backends.ModelBackend',
)

      

blog is the app (correctly installed), auth is the folder in the blogging app, backends.py is the file containing 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 am I getting this error?

ImproperlyConfigured at /signup/
Error importing authentication backend auth.backends: "No module named auth.backends" 

      

+2


a source to share


2 answers


You must have __init__.py

in all used folders (blog and auth)!



+3


a source


Also you may need to clear deleting sessions from django_session; '. I ran into this while updating django versions.



+5


a source







All Articles