title: Django login not working with custom user
body: <p>I have a django project with a custom user (its like <a href="https://www.caktusgroup.com/blog/2013/08/07/migrating-custom-user-model-django/" rel="nofollow">this</a> one so I can use email instead of username). </p>
  
  <p>I am creating an AJAX login but it keeps returning a 500 error which I am finding hard to debug. My code in the view is:</p>
  
  <pre><code>@require_AJAX
  def login(request):
      if request.method == 'POST':
          email = request.POST['email_address']
          password = request.POST['password']
          print email, password
          user = authenticate(email=email, password=password)
          print user
          if user is not None:
              if user.is_active:
                  print 'starting to work'
                  login(request, user)
                  print 'it worked'
  
                  response = HttpResponse(json.dumps({'code':'ok'}), content_type='application/json')
              else:
                  response = HttpResponse(json.dumps({'code':'inactive'}), content_type='application/json')
          else:
              print 'user is none'
              response = HttpResponse(json.dumps({'code':'notok'}), content_type='application/json') 
          return response
  </code></pre>
  
  <p>All the parts work fine except for the one where the user is an active user and then the login(request, user) seems to fail for some reason (I get 'starting to work' printed to console but not 'it worked'.</p>
  
  <p>Does anyone know why this might be or can they suggest how I can get the exception to be shown in the console?</p>