Last active
June 20, 2018 07:01
-
-
Save jerinisready/703b19a2704125c16ba7063bee7e8b6b to your computer and use it in GitHub Desktop.
APIDetailView Django Rest Framework / DRF Detail View With pk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class APIDetailView(APIView): | |
authentication_classes = (CsrfExemptSessionAuthentication, BasicAuthentication) | |
http_method_names = ('get', ) | |
serializer_class = ModelSerializer | |
def get(self, request, pk, **kwargs): | |
obj = Chapter.objects.get(id=pk) | |
serializer = ModelSerializer(obj, context={"request": request}) | |
return Response(serializer.data, status=status.HTTP_200_OK) | |
# urls.py | |
# | |
# url(r'^v1/object/(?P<pk>\d+)/', APIDetailView.as_view(), name='object-get'), | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment