What is the best way to detect the device accessing the page, and use logic to change the display depending on the browser device type?
finally i got the solution:
i use django-mobile for this, change in settings.py
as per requirement and made a middleware.py
for this.
settings.py:(first follow `django-mobile`)
DESKTOP_TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, 'templates'),)
MOBILE_TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, 'templates/mobile'),)
then make middleware.py
middleware.py
from django.conf import settings
class MobileTemplatesMiddleware(object):
"""Determines which set of templates to use for a mobile site"""
def process_request(self, request):
# sets are used here, you can use other logic if you have an older version of Python
MOBILE_SUBDOMAINS = set(['m', 'mobile'])
domain = set(request.META.get('HTTP_HOST', '').split('.'))
if request.flavour=='mobile':
settings.TEMPLATE_DIRS = settings.MOBILE_TEMPLATE_DIRS
else:
settings.TEMPLATE_DIRS = settings.DESKTOP_TEMPLATE_DIRS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With