code: def dispatch(self, request, *args, **kwargs):
          
  
          self.return_url = request.GET.get('return_url', None)
          referrer = request.META.get('HTTP_REFERER', None)
  
          # leave alone POST and ajax requests and if return_url is explicitly left empty
          if (request.method != "GET" or
                  request.is_ajax() or
                  self.return_url or
                  referrer is None or
                  self.return_url is None and 'return_url' in request.GET):
              return super().dispatch(request, *args, **kwargs)
  
          if not self.return_url:
              url = request.get_full_path()
              if url.find("?") < 0:
                  url = "?return_url=".join((url, referrer))
              else:
                  url = "&return_url=".join((url, referrer))
              return HttpResponseRedirect(url)
docs: Does request processing for return_url query parameter and redirects with it's missing
  
          We can't do that in the get method, as it does not exist in the View base class
          and child mixins implementing get do not call super().get