“Django Rest Framework Function Views” Kode Jawaban

Django Rest Framework Function Views

from rest_framework.decorators import api_view, permission_classes, renderer_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.renderers import JSONRenderer
from rest_framework.response import Response

@api_view(['GET'])
@permission_classes([IsAuthenticated])  # policy decorator
@renderer_classes([JSONRenderer])       # policy decorator
def items_not_done(request):
    user_count = Item.objects.filter(done=False).count()
    content = {'not_done': user_count}

    return Response(content)
Ahmed Shimul

Django Rest Framework Viewset

class UserViewSet(viewsets.ModelViewSet):
    """
    A viewset for viewing and editing user instances.
    """
    serializer_class = UserSerializer
    queryset = User.objects.all()
Brayan Prieto

Jawaban yang mirip dengan “Django Rest Framework Function Views”

Pertanyaan yang mirip dengan “Django Rest Framework Function Views”

Lebih banyak jawaban terkait untuk “Django Rest Framework Function Views” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya