You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 27, 2022. It is now read-only.
The profile views are good candidates to reuse some common patterns with Generic Views from Django REST framework and make the code more DRY.
ProfileRetrieveAPIView looks like this:
classProfileRetrieveAPIView(RetrieveAPIView):
permission_classes= (AllowAny,)
queryset=Profile.objects.select_related('user')
renderer_classes= (ProfileJSONRenderer,)
serializer_class=ProfileSerializerdefretrieve(self, request, username, *args, **kwargs):
# Try to retrieve the requested profile and throw an exception if the# profile could not be found.try:
profile=self.queryset.get(user__username=username)
exceptProfile.DoesNotExist:
raiseNotFound('A profile with this username does not exist.')
serializer=self.serializer_class(profile, context={
'request': request
})
returnResponse(serializer.data, status=status.HTTP_200_OK)
Using generic views features, will look like this: