Skip to main content

Mobile Middleware utilities for Turbogears 2 detects mobile browsers

Project description

About Mobile Middleware

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 requests

You will be able to see if your request is coming from a mobile browser with:

from tg import request
request.is_mobile

Enabling Mobile Agents Detection

In your application config/middleware.py import MobileMiddleware:

from tgext.mobilemiddleware import MobileMiddleware

Change your make_app method:

app = make_base_app(global_conf, full_stack=True, **app_conf)
return MobileMiddleware(app, app_conf)

Exposing Mobile Templates

tgext.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 registering a custom template renderer with ‘mobile’ custom format. @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_name

Examples:

@expose('app.templates.index')
@expose_mobile('app.templates.mobile.index')
def index(self, *args, **kw):
    return dict()

Customizing User Agents Detection

MobileMiddleware by default checks user agent with a regular expression that can be customized by changing [app:main] section of your configuration file by adding something like:

mobile.agents = android|fennec|iemobile|iphone|ipod|ipad

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tgext.mobilemiddleware-0.1.tar.gz (3.0 kB view details)

Uploaded Source

File details

Details for the file tgext.mobilemiddleware-0.1.tar.gz.

File metadata

File hashes

Hashes for tgext.mobilemiddleware-0.1.tar.gz
Algorithm Hash digest
SHA256 88cd9128ef1af3a7ec4183dc6b176de8e945f6c2f4af87d9436afe684333d022
MD5 62296547ecfe94de54718f4f3733c710
BLAKE2b-256 a5d86746f17c59b331c509c0414d77f8e9a62c84c41d9b35331b0640c2fd1419

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page