Search code examples
djangodjango-modelsdjango-rest-frameworkdjango-rest-viewsets

Django Rest Frame give 404 not found


When I hit the URL doctor/56b63b2d-11c4-4f0c-be7c-0b0348c487fd/ I get the detail not found I tried every solution but still it' not work

error : - "GET /doctor/56b63b2d-11c4-4f0c-be7c-0b0348c487fd/ HTTP/1.1" 404 11332

class DoctorViewSet(ListModelMixin, RetrieveModelMixin, DestroyModelMixin, UpdateModelMixin, GenericViewSet):
serializer_class = DoctorDeshboardSerializer
def get_queryset(self, *args, **kwargs):
    doctor = self.kwargs["pk"]
    queryset = PatientDetails.objects.filter(doctor=doctor)
    print(queryset)
    return queryset

And I look the get_queryset this has printed the all patient-related to doctor So means my logic is fine and data also exist but

router = DefaultRouter()
router.register('patient', views.PatientDashboardViewSet, basename='patients')
router.register('doctor', views.DoctorViewSet, basename='doctors')
urlpatterns = router.urls

I also show serializer.py

class DoctorDeshboardSerializer(serializers.ModelSerializer):
problem_patient = SimpleProblemPatient(many=True)

class Meta:
    model = PatientDetails
    fields = ['id', 'name', 'problem_patient']

Solution

  • Update your url and try again,

    router.register('doctor/<uuid:pk>/', views.DoctorViewSet, basename='doctors')