Skip to content

Instantly share code, notes, and snippets.

@robertobarreda
Created October 3, 2013 14:09
Show Gist options
  • Save robertobarreda/6810436 to your computer and use it in GitHub Desktop.
Save robertobarreda/6810436 to your computer and use it in GitHub Desktop.
django.request is_mobile?
import re
USER_AGENT_REGEX = re.compile(
r"android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|"
r"ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|"
r"phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|"
r"vodafone|wap|indows (ce|phone)|xda|xiino", re.M)
def is_mobile(request):
ua = request.META.get('HTTP_USER_AGENT', '').lower()
if USER_AGENT_REGEX.search(ua):
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment