def api_view(http_method_names=None, exclude_from_schema=False):
 http_method_names = ([u'GET'] if (http_method_names is None) else http_method_names)
 def decorator(func):
  WrappedAPIView = type(((six.PY3 and u'WrappedAPIView') or 'WrappedAPIView'), (APIView,), {u'__doc__': func.__doc__})
  assert (not isinstance(http_method_names, types.FunctionType)), u'@api_view missing list of allowed HTTP methods'
  assert isinstance(http_method_names, (list, tuple)), (u'@api_view expected a list of strings, received %s' % type(http_method_names).__name__)
  allowed_methods = (set(http_method_names) | set((u'options',)))
  WrappedAPIView.http_method_names = [method.lower() for method in allowed_methods]
  def handler(self, *args, **kwargs):
   return func(*args, **kwargs)
  for method in http_method_names:
   setattr(WrappedAPIView, method.lower(), handler)
  WrappedAPIView.__name__ = func.__name__
  WrappedAPIView.__module__ = func.__module__
  WrappedAPIView.renderer_classes = getattr(func, u'renderer_classes', APIView.renderer_classes)
  WrappedAPIView.parser_classes = getattr(func, u'parser_classes', APIView.parser_classes)
  WrappedAPIView.authentication_classes = getattr(func, u'authentication_classes', APIView.authentication_classes)
  WrappedAPIView.throttle_classes = getattr(func, u'throttle_classes', APIView.throttle_classes)
  WrappedAPIView.permission_classes = getattr(func, u'permission_classes', APIView.permission_classes)
  WrappedAPIView.exclude_from_schema = exclude_from_schema
  return WrappedAPIView.as_view()
 return decorator

def api_view ( http_method_names = None , exclude_from_schema = False ) : http_method_names = ( [ u'GET' ] if ( http_method_names is None ) else http_method_names ) def decorator ( func ) : WrappedAPIView = type ( ( ( six . PY3 and u'WrappedAPIView' ) or 'WrappedAPIView' ) , ( APIView , ) , { u'__doc__' : func . __doc__ } ) assert ( not isinstance ( http_method_names , types . FunctionType ) ) , u'@api_view missing list of allowed HTTP methods' assert isinstance ( http_method_names , ( list , tuple ) ) , ( u'@api_view expected a list of strings, received %s' % type ( http_method_names ) . __name__ ) allowed_methods = ( set ( http_method_names ) | set ( ( u'options' , ) ) ) WrappedAPIView . http_method_names = [ method . lower ( ) for method in allowed_methods ] def handler ( self , * args , ** kwargs ) : return func ( * args , ** kwargs ) for method in http_method_names : setattr ( WrappedAPIView , method . lower ( ) , handler ) WrappedAPIView . __name__ = func . __name__ WrappedAPIView . __module__ = func . __module__ WrappedAPIView . renderer_classes = getattr ( func , u'renderer_classes' , APIView . renderer_classes ) WrappedAPIView . parser_classes = getattr ( func , u'parser_classes' , APIView . parser_classes ) WrappedAPIView . authentication_classes = getattr ( func , u'authentication_classes' , APIView . authentication_classes ) WrappedAPIView . throttle_classes = getattr ( func , u'throttle_classes' , APIView . throttle_classes ) WrappedAPIView . permission_classes = getattr ( func , u'permission_classes' , APIView . permission_classes ) WrappedAPIView . exclude_from_schema = exclude_from_schema return WrappedAPIView . as_view ( ) return decorator
wrapper for calling an api view .