tgext.mobilemiddlewareMobile Middleware utilities for Turbogears 2 detects mobile browsers | |
Download |
tgext.mobilemiddleware Ranking & Summary
Advertisement
- License:
- LGPL
- Publisher Name:
- Alessandro Molina
- Publisher web site:
- http://www.objectblues.net/wiki/show/FlatLand
tgext.mobilemiddleware Tags
tgext.mobilemiddleware Description
Mobile Middleware utilities for Turbogears 2 detects mobile browsers tgext.mobilemiddleware is a mobile middleware is a middleware for WSGI applications.Thought to be used on Turbogears 2 applications it detects mobile browser and provides a way to detect and react to them. Detection expression can be customized and action can change from plain detection to exposing a specific custom template for mobile requestsYou will be able to see if your request is coming from a mobile browser with:from tg import requestrequest.is_mobileInstallingtgext.mobilemiddleware can be installed both from pypi or from bitbucket:easy_install tgext.mobilemiddlewareshould just work for most of the usersEnabling Mobile Agents DetectionIn your application config/middleware.py import MobileMiddleware:from tgext.mobilemiddleware import MobileMiddlewareChange your make_app method:app = make_base_app(global_conf, full_stack=True, **app_conf)return MobileMiddleware(app, app_conf)Exposing Mobile Templatestgext.mobilemiddleware implements a @expose_mobile decorator that works like @expose TurboGears2 decorator which can be used to specify which template to expose for mobie requests.This will work by switching the template before rendering the view if the request is detected to be from a mobile browser. @expose_mobile supports the same template naming convention that @expose uses and can accept any rendering engine that has been registered in turbogears by specifing it as engine:module.template_nameExamples:@expose('app.templates.index')@expose_mobile('app.templates.mobile.index')def index(self, *args, **kw): return dict()Customizing User Agents DetectionMobileMiddleware by default checks user agent with a regular expression that can be customized by changing section of your configuration file by adding something like:mobile.agents = android|fennec|iemobile|iphone|ipod|ipad Requirements: · Python
tgext.mobilemiddleware Related Software