title: Django rest framework custom Response middleware
body: <p>I use Django Rest Framework with rest_auth (/login, /logout/, /register...)
  I have a Middleware, normally triggered by user_logged_in or user_logged_out signals.  </p>
  
  <p>In my Middleware, I want to use Response object from Rest framework. </p>
  
  <p>My middleware.py</p>
  
  <pre><code>from django.contrib.sessions.models import Session
  from django.contrib.auth import logout
  from django.contrib.auth.models import AnonymousUser
  from rest_framework.response import Response
  from rest_framework import status
  
  
  class OneSessionPerUserMiddleware:
      def __init__(self, get_response):
  
          self.get_response = get_response
  
      def __call__(self, request):
  
          if request.user.is_authenticated:
              if request.user.session_key != Session.objects.filter(session_key__in = request.user.session_key):
                  logout(request)
                  return Response(request)
          return self.get_response(request)
  </code></pre>
  
  <p>I suppose that I pass my condition,  but I get this error : </p>
  
  <pre><code> The response content must be rendered before it can be accessed
  </code></pre>
  
  <p>How to use correctly the API Response object in a middleware ?<br>
  And I don't understand really what is : self.get_response = get_response ? </p>