I have a custom user in a Django 1.5 project, which uses the email field as the username:
class MyUser(AbstractUser): my_custom_field = models.CharField(max_length=20, blank=True, null=True) USERNAME_FIELD = 'email' MyUser._meta.get_field_by_name('email')[0]._unique = True MyUser.REQUIRED_FIELDS.remove('email') If I try to authenticate that user like so:
auth_user = authenticate(username=email, password=password) login(request, auth_user) I get this:
Traceback: File "/Users/user/dev/proj/app/core/views.py" in post 39. login(request, auth_user) File "/Users/user/.virtualenvs/proj/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in login 92. request.session[BACKEND_SESSION_KEY] = user.backend File "/Users/user/.virtualenvs/proj/lib/python2.7/site-packages/django/utils/functional.py" in inner 203. return func(self._wrapped, *args) Exception Type: AttributeError at /signup Exception Value: 'AnonymousUser' object has no attribute 'backend' How am I supposed to authenticate a custom user?
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend')AUTH_USER_MODEL?authenticatedoesn't seem to be returning an actual User. Is it the standard method from django.contrib.auth? Are you sure email and password are correct?AUTH_USER_MODELset toappname.MyUserandfrom django.contrib.auth import authenticate, login, email and password are correct since I just created the user earlier in that flowcreate_user()forMyUser?