docs: def ajax_request(func):
      """
      If view returned serializable dict, returns response in a format requested
      by HTTP_ACCEPT header. Defaults to JSON if none requested or match.
  
      Currently supports JSON or YAML (if installed), but can easily be extended.
  
      example:
  
          @ajax_request
          def my_view(request):
              news = News.objects.all()
              news_titles = [entry.title for entry in news]
              return {'news_titles': news_titles}
      """
      @wraps(func)
      def wrapper(request, *args, **kwargs):
          for accepted_type in request.META.get('HTTP_ACCEPT', '').split(','):
              if accepted_type in FORMAT_TYPES.keys():
                  format_type = accepted_type
                  break
          else:
              format_type = 'application/json'
          response = func(request, *args, **kwargs)
          if not isinstance(response, HttpResponse):
              if hasattr(settings, 'FORMAT_TYPES'):
                  format_type_handler = settings.FORMAT_TYPES[format_type]
                  if hasattr(format_type_handler, '__call__'):
                      data = format_type_handler(response)
                  elif isinstance(format_type_handler, six.string_types):
                      mod_name, func_name = format_type_handler.rsplit('.', 1)
                      module = __import__(mod_name, fromlist=[func_name])
                      function = getattr(module, func_name)
                      data = function(response)
              else:
                  data = FORMAT_TYPES[format_type](response)
              response = HttpResponse(data, content_type=format_type)
              response['content-length'] = len(data)
          return response
      return wrapper