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
Installing
tgext.mobilemiddleware can be installed both from pypi or from bitbucket:
easy_install tgext.mobilemiddleware
should just work for most of the users
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 mobile 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 specifying 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
If you want to quickly customize the regular expression used to detect the mobile browser you can define mobile.agents configuration variable in your application config file and set it to the regular expression that you want to use.
For more complex customizations, you may create your own subclass of DetectMobileBrowser, or callable object and supply it as an argument to MobileMiddleware, like:
return MobileMiddleware(app, app_conf, mobile_browser_detector=YourClass)
DetectMobileBrowser behaviour can be changed by any subclass by overridding the DetectMobileBrowser.perform_detection method. If user has defined a custom regular expression it will be available inside the perform_detection method as self.custom_mobile_re
Metadata
Release files for tgext.mobilemiddleware 0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tgext.mobilemiddleware-0.4.tar.gz | 5.0 kB | Without provenance | Details for tgext.mobilemiddleware-0.4.tar.gz |
Release files / tgext.mobilemiddleware-0.4.tar.gz
| Download URL | tgext.mobilemiddleware-0.4.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6f52aee1ef3ebadfba41c295735768231c150effbc89c80d7c33aa1bfdca7fc0
|
|
BLAKE2b-256 checksum How to use checksums |
a622b385657211db8b885b5bf8b8f778a627598c08304b2caf85f36d36257379
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for tgext.mobilemiddleware 0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.