title: Django Conditional login redirect
body: <p>This is my middleware which is continuously redirecting.
  How can i give conditional redirecting in my middleware? and instead of path name how can i get <code>path_name</code>.</p>
  
  <p>middleware.py</p>
  
  <pre><code>class PermissionRequiredMiddleware:
     def __init__(self, get_response):
         self.get_response = get_response
  
     def __call__(self, request):
         response = self.get_response(request)
         return response
  
     def process_view(self, request, view_func, view_args, view_kwargs):
  
         assert hasattr(request, 'user')
         path = request.path_info
  
         if request.user.is_authenticated:
             if request.user.userprofile.user_role.id == 1 :
                 return redirect('superadmin_dashboard')
             elif request.user.userprofile.user_role.id == 2 :
                 return redirect('admin_dashboard')
             elif request.user.userprofile.user_role.id == 3 :
                 return redirect('admin_dashboard')
             elif request.user.userprofile.user_role.id == 4 :
                 return redirect('admin_dashboard')
  </code></pre>