Login

mini_render_to_response

Author:
menendez
Posted:
April 19, 2009
Language:
Python
Version:
1.0
Tags:
templates render iphone mini
Score:
0 (after 0 ratings)

You need the mini-detector middleware installed http://www.iterasi.net/openviewer.aspx?sqrlitid=-e2dfig9w0yrclxaigp-uw.

This is a drop in replacement to render_to_response. When using mini_render_to_response it will try to load a version of your template with mini at the end. For example "home_mini.html" instead of "home.html". If it doesn't find the _mini version it falls back to the regular "home.html" version of your template.

Easy way to maintain a "small screen" version of your templates for iPhone or other small screen devices.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
def mini_render_to_response(template, context, context_instance, try_mobile = True, *args, **kwargs):
    render = None
    if try_mobile and context_instance['request'].GET.has_key('mini'):
        try:
            file, ext = template.split('.')
        except ValueError: pass
        else:
            mini_template = file + '_mini.' + ext
            try:
                render = render_to_response(mini_template, context, context_instance=context_instance, *args, **kwargs)
            except TemplateDoesNotExist: pass
    
    if not render:
        render = render_to_response(template, context, context_instance=context_instance, *args, **kwargs)
    
    return render

More like this

  1. Detect iPhone & Switch Template via render_to_response by bryanhelmig 4 years, 10 months ago
  2. iPhoneMiddleware by henriklied 6 years, 6 months ago
  3. Simple Mobile Support by bahoo 4 years, 5 months ago
  4. Mobile browser detection middleware by pavl 4 years, 11 months ago
  5. User groups template tag by davea 3 years, 5 months ago

Comments

Please login first before commenting.