Skip to content

Instantly share code, notes, and snippets.

@mattgorecki
Created May 16, 2011 17:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattgorecki/974920 to your computer and use it in GitHub Desktop.
Save mattgorecki/974920 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)
@mattgorecki
Copy link
Author

This is for changing the view in web2py based on the browser agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment