Our site can be accessed from a full browser, from mobile browsers and from a custom iPhone application. Since the logic is basically the same regardless of the client, we use the same views to handle all types of requests. But at the bottom of each of our views, we have something like:
if request.is_mobile(): return render_to_response('foo/bar/baz_mobile.html', context) elif request.is_api(): return json.dumps(context) else: return render_to_response('foo/bar/baz.html', context)
Clearly there is a better way to do this :)
I thought that our views return a context dictionary and wrap them in a decorator that determines how to display the response. Alternatively, there might be something that I can do with class based views.
How do you do this?
source share