Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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)

classRequestMiddleware():
    defprocess_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 = Trueelse:
                 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">Watchout! You'reusingIE, 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]-->

Solution 2:

There is another way! Just use settings variable DISALLOWED_USER_AGENTS, and make sure that CommonMiddleware is installed on your site.

For example

import re
DISALLOWED_USER_AGENTS = (re.compile(r'msie\s*[2-7]', re.IGNORECASE), )

Cheers!

Post a Comment for "How To Block Internet Explorer On My Django Web App?"