Search code examples
pythondjangopython-3.xdjango-2.2

Django Error Handling for Browser Support


I wanted to handle browser support. If the browser does not support the website, I would like to be redirected to a custom template. How do I find out if the browser supports it or not can anyone help me.?


Solution

  • The information about what the browser claims itself to be is available in request.META['HTTP_USER_AGENT'], which you can use to redirect to an error screen "We do not support Internet Exploiter 5" or whatever. Or, to conditionalize your template rendering for Edge cases (sorry MS, couldn't resist).

    You can of course also write more-or-less concealed Javascripts to test that the browser correctly handles some feature that you absolutely require (for example, that JavaScript is not disabled, that cookies are accepted ... )