1. Ron Cohen
  2. django_mobile_utils

Source

django_mobile_utils / mobile_utils / loaders.py

from os.path import join
from django.conf import settings
from django.template import TemplateDoesNotExist
from mobile_utils.middleware import get_current_request


def load_template_source(template_name, template_dirs=None):
    request = get_current_request()
    if hasattr(request, 'is_mobile') and request.is_mobile:
        try:
            filepath = join(settings.PROJECT_PATH, "mobile_templates", template_name)
            file = open(filepath)
            try:
                return (file.read(), filepath)
            finally:
                file.close()
        except IOError:
                pass

    raise TemplateDoesNotExist(template_name)
load_template_source.is_usable = True