Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block internet explorer on my Django web app?

I'm working on a web application that does not work well with Internet Explorer (web socket, json, security issues).

For now, before my application works with IE:

How can I refuse connections coming from Internet Explorer client ?

Thank you

like image 360
Guillaume Vincent Avatar asked Feb 15 '23 11:02

Guillaume Vincent


1 Answers

Create a middleware where you're parsing the request.META['HTTP_USER_AGENT']. If you found that the user use IE, give him a nice message (e.g a notification or a little alert box) to says him that your site isn't optimized for his browser :)

Some code example: Django way

middleware.py (see the doc for more information)

class RequestMiddleware():
    def process_request(self, request):
        if request.META.has_key('HTTP_USER_AGENT'):
            user_agent = request.META['HTTP_USER_AGENT'].lower()
            if 'trident' in user_agent or 'msie' in user_agent:
                 request.is_IE = True
            else:
                 request.is_IE = False

           # or shortest way:
           request.is_IE = ('trident' in user_agent) or ('msie' in user_agent)

your base template:

{% if request.is_IE %}<div class="alert">Watch out! You're using IE, but unfortunately, this website need HTML5 features...</div>{% endif %}

And then add it to your middlewares list.

Optimized: pure HTML way

If you only want to display a message like what I've done, you can use a HTML conditional comment:

<!--[if IE]> <div class="alert">...</div><![endif]-->
like image 51
Maxime Lorant Avatar answered Feb 23 '23 15:02

Maxime Lorant