Skip to content

Instantly share code, notes, and snippets.

@tazjel
Forked from mattgorecki/gist:974920
Created May 29, 2011 13:38
Show Gist options
  • Save tazjel/997786 to your computer and use it in GitHub Desktop.
Save tazjel/997786 to your computer and use it in GitHub Desktop.
web2py mobile browser detection
# Detect mobile device. Set to mobile view if available
from mobile.sniffer.detect import detect_mobile_browser
if detect_mobile_browser(request.env.http_user_agent):
mobile_view = '%s.mobile.%s' % (request.function, request.extension)
if os.path.exists(os.path.join(request.folder, 'views',request.controller, mobile_view)):
response.view = '%s/%s' % (request.controller, mobile_view)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment