text: from django.http import Http404
  from django.contrib.auth import get_user_model
  
  from rest_framework import generics, mixins, viewsets
  from rest_framework.renderers import StaticHTMLRenderer
  from rest_framework.permissions import IsAuthenticatedOrReadOnly
  from rest_framework.decorators import api_view
  from rest_framework.reverse import reverse
  from rest_framework.response import Response
  
  from .models import Snippet
  from .serializers import SnippetSerializer, UserSerializer
  from .permissions import IsOwnerOrReadOnly
  
  User = get_user_model()
  
  def action(methods=None, detail=None, url_path=None, url_name=None, **kwargs):
      """
      Mark a ViewSet method as a routable action.
      Set the `detail` boolean to determine if this action should apply to
      instance/detail requests or collection/list requests.
      """
      methods = ['get'] if (methods is None) else methods
      methods = [method.lower() for method in methods]
  
      assert detail is not None, (
          "@action() missing required argument: 'detail'"
      )
  
      def decorator(func):
          func.bind_to_methods = methods
          func.detail = detail
          func.url_path = url_path if url_path else func.__name__
          func.url_name = url_name if url_name else func.__name__.replace('_', '-')
          func.kwargs = kwargs
          return func
      return decorator
  
  @api_view(['GET'])
  def api_root(request, format=None):
      return Response({
          'users': reverse('snippets:user-list', request=request, format=format),
          'snippets': reverse('snippets:snippet-list', request=request, format=format) 
      })
  
  
  class SnippetViewSet(viewsets.ModelViewSet):
      queryset = Snippet.objects.all()
      serializer_class = SnippetSerializer
      permission_classes = [IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
  
      @action(detail=True, renderer_classes = (StaticHTMLRenderer,))
      def highlight(self, request, *args, **kwargs):
          snippet = self.get_object()
          return Response(snippet.highlighted)
  
      def perform_create(self, serializer):
          serializer.save(owner=self.request.user)
  
  
  class UserViewSet(viewsets.ReadOnlyModelViewSet):
      queryset = User.objects.all()
      serializer_class = UserSerializer
  
  # class SnippetListCreateView(generics.ListCreateAPIView):
  #     queryset = Snippet.objects.all()
  #     serializer_class = SnippetSerializer
  #     permission_classes = [IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
  
  #     def perform_create(self, serializer):
  #         serializer.save(owner=self.request.user)
  
  
  # class SnippetRUDView(generics.RetrieveUpdateDestroyAPIView):
  #     queryset = Snippet.objects.all()
  #     serializer_class = SnippetSerializer
  #     permission_classes = [IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly]
  
  
  # class SnippetHighlight(generics.GenericAPIView):
  #     queryset = Snippet.objects.all()
  #     renderer_classes = (StaticHTMLRenderer,)
  
  #     def get(self, request, *args, **kwargs):
  #         snippet = self.get_object()
  #         return Response(snippet.highlighted)
  
  # class UserListView(generics.ListAPIView):
  #     queryset = User.objects.all()
  #     serializer_class = UserSerializer
  
  
  # class UserDetailView(generics.RetrieveAPIView):
  #     queryset = User.objects.all()
  #     serializer_class = UserSerializer
  