title: django exclude urls using regular expression in list
body: <p>I'm working on <code>Middleware</code> in django version 2.1. It is <code>LoginMiddleWare</code> where i need to exclude some urls if the <code>requested url exits</code> it returns <code>None</code></p>
  
  <p>below is the portion of middleware code : middleware.py</p>
  
  <pre><code>def process_view(self, request, view_func, view_args, view_kwargs):
      exclude_urls = [r'[admin]', r'[login]', r'[register]', r'[demo]']
  
      if(request.path_info in exclude_urls):
          print('BELOW IS EXCLUDED URL')
          print(request.path_info)
          return None
      else:
          print('BELOW IS NOT EXCLUDED URL')
          print(request.path_info)
  </code></pre>
  
  <p>The above code must identify the url requested by user <code>request.path_info</code> and must check exits in <code>exclude_urls</code> </p>
  
  <p>EXAMPLE : if requested url is <code>https://www.example.com/login?query=1</code> this must identify <code>login</code> in that particular url and must return <code>None</code></p>
  
  <h2>EDIT 1</h2>
  
  <p>After reviewing my code here below came with a solution  </p>
  
  <pre><code>    url_list = [
          'admin/login',
          '/demo/login'
      ]
  
      requested_path = request.path_info
      print('requested path :'+requested_path)
      for i in url_list:
          r1 = re.findall(r'^'+requested_path, i)
          print(len(r1))
  
          if len(r1) &gt; 0:
              return None
          else:
              if not request.session.get('user_logged', None):
                  print("Session Empty")
                  return redirect('login') //HERE USER IS GOING INTO CONTINUOUS REDIRECT LOOP HOW CAN I STOP INFINITE REDIRECTS
              else:
                  print("Session Exits")
  </code></pre>
  
  <p>THE ABOVE CHANGES IN CODE WORKS IN SOME EXTEND <code>NOW THE ISSUE IS IT REDIRECTING TO https://www.example.com/demo/login</code> page again and again how can i stop this. </p>
  
  <h2>EDIT 2</h2>
  
  <p>What i'm looking to achieve </p>
  
  <p><code>admin/login and demo/login</code> currently are the two urls i need to exclude while check if <code>session exits in middleware.py</code></p>
  
  <p>CASE 1 : 
            IF URL EXISTS IN LIST AND SESSION IS EMPTY AND USER HAS <code>REQUESTED demo/login</code> url the i need him to redirect to his url <code>demo/login</code> url</p>
  
  <p>CASE 2 :
            IF USER REQUESTED URL IS OTHER THAN URL MENTIONED IN <code>list url_list</code>. IN  THE ELSE I'M CHECKING IF SESSION IS EMPTY THEN I'M REDIRECTING USER TO <code>demo/login</code> page[## BUT USER IS GOING INTO CONTINUOUS REDIRECT LOOP HOW CAN I STOP INFINITE REDIRECTS ##]</p>
  
  <h2>THANKS IN ADVANCE</h2>