def render(obj, template=None): mimetypes = request.accept_mimetypes best = mimetypes.best_match(['text/html', 'application/json'], 'application/json') if best == 'application/json': json_obj = recursive_encoder(obj) return jsonify(json_obj) return render_template(template, data=obj)
def bson_renderer(objects, template=None, ctx=None): data = recursive_encoder(objects) return dumps(data, default=to_json)