title: AttributeError at /logout/ 'tuple' object has no attribute 'backend'
body: <p>I used Python3 in windows 10 to write a django2 web app.
  I tried to configure the LDAP login, but failed.
  When I test using postman, it could get the reply successfully.
  That is, I send a request to <a href="https://example.com/staff" rel="nofollow noreferrer">https://example.com/staff</a>, with some authentication code and payload containing username and password, and it reply me with the LDAP reply.</p>
  <p>However, when I tried to using ldap3 in Django, after successfully login, error shows:</p>
  <pre><code>AttributeError at /logout/
  'tuple' object has no attribute 'backend'
  </code></pre>
  <p>code:
  settings.py:</p>
  <pre><code>AUTHENTICATION_BACKENDS = (
  'app.backends.LDAPBackend',
  ('django.contrib.auth.backends.ModelBackend'),
  )
  </code></pre>
  <p>app/backends.py:</p>
  <pre><code>from django.contrib.auth import get_user_model    
  UserModel = get_user_model()
  
  class LDAPBackend:
  
  def authenticate(self, request, username=None, password=None, **kwargs):
  
      try:      
          headers = {'Authorization': xxxxx}        
          body = {&quot;username&quot;: username, &quot;password&quot;: password}    
          response = requests.post(url=&quot;https://example.com/staff&quot;, json=body, headers=headers)
          result = response.json()
          print(result)     
          if result['code'] != &quot;OK&quot;:
  
              logger.info(&quot;Wrong Login Information&quot;)
              return None
          print(&quot;connected&quot;)
      except Exception as e:
          print(e)
      user = UserModel.objects.update_or_create(username=username)
      return user
  
  def get_user(self, user_id):
      try:
          return UserModel._default_manager.get(pk=user_id)
      except UserModel.DoesNotExist:
          return None
  </code></pre>
  <p>error shows: AttributeError at /logout/ 'tuple' object has no attribute 'backend', below shows result in console:</p>
  <pre><code>   connected
  Internal Server Error: /logout/
  Traceback (most recent call last):
    File &quot;C:\Users\software\python\lib\site-packages\django\core\handlers\exception.py&quot;, line 34, in inner
      response = get_response(request)
    File &quot;C:\Users\software\python\lib\site-packages\django\core\handlers\base.py&quot;, line 115, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File &quot;C:\Users\software\python\lib\site-packages\django\core\handlers\base.py&quot;, line 113, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\views\generic\base.py&quot;, line 71, in view
      return self.dispatch(request, *args, **kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\utils\decorators.py&quot;, line 45, in _wrapper
      return bound_method(*args, **kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\views\decorators\debug.py&quot;, line 76, in sensitive_post_parameters_wrapper
      return view(request, *args, **kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\utils\decorators.py&quot;, line 45, in _wrapper
      return bound_method(*args, **kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\utils\decorators.py&quot;, line 142, in _wrapped_view
      response = view_func(request, *args, **kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\utils\decorators.py&quot;, line 45, in _wrapper
      return bound_method(*args, **kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\views\decorators\cache.py&quot;, line 44, in _wrapped_view_func
      response = view_func(request, *args, **kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\contrib\auth\views.py&quot;, line 61, in dispatch
      return super().dispatch(request, *args, **kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\views\generic\base.py&quot;, line 97, in dispatch
      return handler(request, *args, **kwargs)
    File &quot;C:\Users\software\python\lib\site-packages\django\views\generic\edit.py&quot;, line 141, in post
      if form.is_valid():
    File &quot;C:\Users\software\python\lib\site-packages\django\forms\forms.py&quot;, line 185, in is_valid
      return self.is_bound and not self.errors
    File &quot;C:\Users\software\python\lib\site-packages\django\forms\forms.py&quot;, line 180, in errors
      self.full_clean()
    File &quot;C:\Users\software\python\lib\site-packages\django\forms\forms.py&quot;, line 382, in full_clean
      self._clean_form()
    File &quot;C:\Users\software\python\lib\site-packages\django\forms\forms.py&quot;, line 409, in _clean_form
      cleaned_data = self.clean()
    File &quot;C:\Users\software\python\lib\site-packages\django\contrib\auth\forms.py&quot;, line 205, in clean
      self.user_cache = authenticate(self.request, username=username, password=password)
    File &quot;C:\Users\software\python\lib\site-packages\django\contrib\auth\__init__.py&quot;, line 80, in authenticate
      user.backend = backend_path
  AttributeError: 'tuple' object has no attribute 'backend'
  [22/Mar/2021 09:49:10] &quot;POST /logout/ HTTP/1.1&quot; 500 149071
  </code></pre>