def endpoint(fn):
    """
    Wrap the API endpoint.
    """
    def wrap(request, **kwargs):
        try:
            json = dumps(
                fn(request, **kwargs),
                cls=ObjectEncoder,
                request=request,
            )
        except APIException as e:
            json = dumps({
                'error': smart_text(e),
            })
        if 'debug' in request.GET:
            return render(request, 'api/v1_2/debug.html', {
                'title': '2buntu API Debugger',
                'parent': {
                    'title': 'API',
                    'url': reverse('api:index'),
                },
                'json': dumps(loads(json), indent=4),
            })
        elif 'callback' in request.GET:
            return HttpResponse(
                '%s(%s)' % (request.GET['callback'], json),
                content_type='application/javascript; charset=utf-8',
            )
        else:
            return HttpResponse(json, content_type='application/json')
    return wrap
dataset/ETHPy150Open 2buntu/2buntu-blog/twobuntu/api/v1_2/views.py/endpoint/original