MIDDLEWARE_CLASSES = (
# other middlewares...
'django_user_agents.middleware.UserAgentMiddleware',
)
INSTALLED_APPS = (
# Other apps...
'django_user_agents',
)
# Cache backend is optional, but recommended to speed up user agent parsing
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
}
}
# Name of cache backend to cache user agents. If it not specified default
# cache alias will be used. Set to `None` to disable caching.
USER_AGENTS_CACHE = 'default'
Usage is pretty simple as well.
A user_agent attribute will now be added to request, which you can use in views.py:
<!--[if IE]>
<div>
This site is not rendered properly with Internet Explorer.
Please use Firefox instead
</div>
<![endif]-->
As warned by the documentation:
As of Internet Explorer 10, conditional comments are no longer
supported by standards mode. Use feature detection to provide
effective fallback strategies for website features that aren't
supported by the browser
I tested it in IE7, IE9, IE10 and IE11. The only version where this did not work was IE10...