Home > front end >  view sets throwing pagenotfound! found Django DRF
view sets throwing pagenotfound! found Django DRF

Time:10-09

Getting page not found error, trying DRF, I am trying these viewsets but so far error as mentioned thanks in advance!

urlpatterns = [
    path('',include(router.urls)),
    path('organisation_list/',OrganisationList.as_view()),
]

Routes

router = DefaultRouter()
router.register(r'list_organisation',OrganisationViewSet)




class OrganisationViewSet(ViewSet):

    permission_classes = []
    authentication_classes = []

    queryset = Organisation.objects.all()
   
    @action(detail=False, methods=['get'])
    def list_organisations(self,request,*args,**kwargs):
        print('working')
        data = self.queryset
        serializer = OrganisationSerializer(data,many=True)
        return Response(serializer.data,status=200)

error

 "GET /list_organisation/ HTTP/1.1" 404 3548

CodePudding user response:

Since the view list_organisations was defined as a custom action, the actual url for it is:

list_organisation/list_organisations

If you want list_organisation/, just change the view to list:

class OrganisationViewSet(ViewSet):
    ...
    def list(self, request, *args, **kwargs):
        print('working')
        data = self.queryset
        serializer = OrganisationSerializer(data,many=True)
        return Response(serializer.data,status=200)
  • Related