Search code examples
djangoauthenticationnonetype

Django Authenticate returns None


I have the following code snippet:

user = User(username='[email protected]',email='[email protected]')
user.set_password('pass')
user.save()
u = authenticate(username='[email protected]', password='pass') #this always returns None!!!

The problem is, u is always None. I've followed code samples on other stack overflow posts and have narrowed it down to the above lines.

Any ideas as to what might be happening?


Solution

  • Put something like this in your settings

    #Authentication backends
    AUTHENTICATION_BACKENDS = (
            'django.contrib.auth.backends.ModelBackend',
        )
    

    or if you are using userena for your accounts

    #Authentication backends
    AUTHENTICATION_BACKENDS = (
        'userena.backends.UserenaAuthenticationBackend',
        'guardian.backends.ObjectPermissionBackend',
        'django.contrib.auth.backends.ModelBackend',
    )