Our site can be accessed from a full browser, from mobile browsers, and from a custom iPhone app. Since the logic is mostly the same regardless of the client, we're using the same views to process all types of requests. But at the bottom of every one 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's a better way to do it :)
I've thought of just having our views return the context dictionary, and wrapping them in a decorator that determines how to render the response. Alternatively, maybe there's something I can do with class-based views.
How would you do it?