Detect iPhone & Switch Template via render_to_response

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from django.shortcuts import render_to_response as render_to_response_pre

def render_to_response(template, context):
    '''
    If the exisiting view uses a template named foo.html, any iPhone
    will trigger the template named foo-iphone.html.
    '''
    if 'HTTP_USER_AGENT' in context['request'].META:
        if 'iphone' in context['request'].META['HTTP_USER_AGENT'].lower():
            template = template.rstrip('.html')
            template += '-iphone.html'
    return render_to_response_pre(template, context)

More like this

  1. Mobile browser detection middleware by pavl 3 years, 12 months ago
  2. Simple Mobile Support by bahoo 3 years, 6 months ago
  3. iPhoneMiddleware by henriklied 5 years, 6 months ago
  4. Mobile Device Middleware by stephen_mcd 3 years, 11 months ago
  5. mini_render_to_response by menendez 5 years ago

Comments

(Forgotten your password?)