title: Using UserPassesTestMixin (class based view) AND redirect as well
body: <p>I'm trying to instead use the Class based view, and all I end up with the default 403 Forbidden page.. Is the order of the mixin classes correct? Does the code even get used -as in get/post or does everything get bypassed and the default 403 redirect occur?</p>
  
  <p>All working examples seen so far, only point to the decorator @login_required in a function based view and use the request object to redirect to the login page.
  The <a href="https://docs.djangoproject.com/en/2.1/topics/auth/default/#redirecting-unauthorized-requests-in-class-based-views" rel="noreferrer">documentation</a> provides some tips, but I can't get it to work with the code below.. Putting the error stack as well.</p>
  
  <p>check </p>
  
  <pre><code> "GET / HTTP/1.1" 200 2580
  Forbidden (Permission denied): /app/custom-view
  Traceback (most recent call last):
    File "C:\Users\me\.envs\project\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
      response = get_response(request)
    File "C:\Users\me\.envs\project\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "C:\Users\me\.envs\project\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "C:\Users\me\.envs\project\lib\site-packages\django\views\generic\base.py", line 68, in view
      return self.dispatch(request, *args, **kwargs)
    File "C:\Users\me\.envs\project\lib\site-packages\django\contrib\auth\mixins.py", line 52, in dispatch
      return super().dispatch(request, *args, **kwargs)
    File "C:\Users\me\.envs\project\lib\site-packages\django\contrib\auth\mixins.py", line 108, in dispatch
      return self.handle_no_permission()
    File "C:\Users\me\.envs\project\lib\site-packages\django\contrib\auth\mixins.py", line 43, in handle_no_permission
      raise PermissionDenied(self.get_permission_denied_message())
  django.core.exceptions.PermissionDenied
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code> class UserIsAdminMixin(UserPassesTestMixin):
          def test_func(self):
              return request.user.groups.filter(name='CustomAdmin').exists()
  
      class CustomAdminView(LoginRequiredMixin, UserIsAdminMixin, TemplateView):
          template_name = 'template.html'
          # login_url = '/login/'
          # redirect_field_name = 'my_link_name'
  
          def get(self, request):
              form = CustomForm()
              # This does not work neither does setting up login_url 
              if not request.user.is_authenticated or not request.user.is_staff or not self.request.user.groups.filter(name='CustomAdmin').exists():
                  return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
  </code></pre>
  
  <p>I am willing to trying out <a href="https://stackoverflow.com/questions/47095161/use-loginrequiredmixin-and-userpassestestmixin-at-the-same-time/47095406#47095406">this solution</a>, if the above approach doesn't work</p>