Skip to content

Instantly share code, notes, and snippets.

@le717
Created July 17, 2019 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le717/a7b1d396d5dd9bbecb5d8b51a34a3acf to your computer and use it in GitHub Desktop.
Save le717/a7b1d396d5dd9bbecb5d8b51a34a3acf to your computer and use it in GitHub Desktop.
@current_app.before_request
def detect_ie_browser():
"""Redirect all IE visitors to a special page
informing them to get a web browser.
"""
# For this to work, the following conditions must be met:
# 1. The visitor is using IE (doesn't matter what version)
# 2. We must not be currently requesting a static file
# (we still need page styles/resources to load)
# 3. We don't need to be directly requesting the special page
# (we create an endless redirect loop)
if (
request.user_agent.browser == "msie" and
request.endpoint != "static" and
request.endpoint != "special.unsupported_browser"
):
return redirect(url_for("special.unsupported_browser"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment