code: def get_redirect_url(self, **kwargs):
          
          if self.request.REQUEST.has_key('next'): 
              return self.request.REQUEST.get('next')
          url = RedirectView.get_redirect_url(self, **kwargs)
          if url:
              return url
          return self.request.META.get('HTTP_REFERER')
docs: Redirect to request parameter 'next' or to referrer if url is not defined.