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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.