Created
October 3, 2013 14:09
-
-
Save robertobarreda/6810436 to your computer and use it in GitHub Desktop.
django.request is_mobile?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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