Posted By

eternal_fame on 08/21/13


Tagged

ie python django middleware


Versions (?)

Internet Explorer detection Middleware


 / Published in: Django
 

this middleware detects if user tries to access the site using internet explorer older than 8 version

  1. import re
  2. from django.http import HttpResponse
  3.  
  4.  
  5. class IEDetectionMiddleware(object):
  6. """
  7. middleware to detect if the user is on old IE
  8. """
  9.  
  10. def process_request(self, request):
  11. is_ie = False
  12.  
  13. if request.META.has_key('HTTP_USER_AGENT'):
  14. user_agent = request.META['HTTP_USER_AGENT']
  15.  
  16. # Test IE 1-7
  17. pattern = "msie [1-7]\."
  18. prog = re.compile(pattern, re.IGNORECASE)
  19. match = prog.search(user_agent)
  20.  
  21. if match:
  22. is_ie = True # NOOOOOO
  23.  
  24. if is_ie == True:
  25. return HttpResponse("You shall not pass!")

Report this snippet  

You need to login to post a comment.