def allow_jsonp(handler):
 def allow_jsonp_wrapper_fn(request, *args, **kwargs):
  if (('callback' in request.REQUEST) and (request.method == 'OPTIONS')):
   response = HttpResponse('', content_type='text/plain')
  else:
   response = handler(request, *args, **kwargs)
   if (not isinstance(response, JsonResponse)):
    return response
   elif ('callback' in request.REQUEST):
    response = JsonpResponse(response.content, request.REQUEST['callback'])
  if (('callback' in request.REQUEST) and (request.method in ['OPTIONS', 'GET']) and ('HTTP_ORIGIN' in request.META)):
   response['Access-Control-Allow-Origin'] = request.META['HTTP_ORIGIN']
   response['Access-Control-Allow-Methods'] = 'GET, OPTIONS'
   response['Access-Control-Max-Age'] = '1000'
   response['Access-Control-Allow-Headers'] = 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since'
  return response
 return allow_jsonp_wrapper_fn

def allow_jsonp ( handler ) : def allow_jsonp_wrapper_fn ( request , * args , ** kwargs ) : if ( ( 'callback' in request . REQUEST ) and ( request . method == 'OPTIONS' ) ) : response = HttpResponse ( '' , content_type = 'text/plain' ) else : response = handler ( request , * args , ** kwargs ) if ( not isinstance ( response , JsonResponse ) ) : return response elif ( 'callback' in request . REQUEST ) : response = JsonpResponse ( response . content , request . REQUEST [ 'callback' ] ) if ( ( 'callback' in request . REQUEST ) and ( request . method in [ 'OPTIONS' , 'GET' ] ) and ( 'HTTP_ORIGIN' in request . META ) ) : response [ 'Access-Control-Allow-Origin' ] = request . META [ 'HTTP_ORIGIN' ] response [ 'Access-Control-Allow-Methods' ] = 'GET, OPTIONS' response [ 'Access-Control-Max-Age' ] = '1000' response [ 'Access-Control-Allow-Headers' ] = 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since' return response return allow_jsonp_wrapper_fn
a general wrapper for api views that should be permitted to return jsonp .