Not getting the URL of Update api

45 views
Skip to first unread message

Ashutosh Mishra

unread,
Oct 12, 2020, 7:52:25 AM10/12/20
to Django REST framework
I have create update api in django,but i am not getting its api link in postman
urls.py
from rest_framework.routers import DefaultRouter
from doctor import views
from .views import*
router=DefaultRouter()
router.register(r'Patient', views.PatViewSet, basename='PatViewSet')
router.register(r'Sch', views.TotalViewSet, basename='TotalViewSet')
router.register(r'Doctor', views.DocViewSet, basename='DocViewSet')

urlpatterns = router.urls

views.py
class TotalViewSet(viewsets.ViewSet):
def update(self,request,pk=None):
try:
data=request.data
doctor=Doctor.objects.get(pk=pk)
print(doctor)
timings=data.get('schedule')
DAYS=Schedule.DAYS
for day in DAYS:
sch=Schedule()
sch.doctor=doctor
sch.days=day[0]
sch.start_time=timings[day[1]]['start_time']
sch.end_time=timings[day[1]]['end_time']
sch.save()
return Response({"success": True}, status=status.HTTP_200_OK)
except Exception as error:
#traceback.print_exc()
return Response({"message": str(error), "success": False}, status=status.HTTP_200_OK)

Matemática A3K

unread,
Oct 12, 2020, 2:04:54 PM10/12/20
to django-res...@googlegroups.com
On Mon, Oct 12, 2020 at 6:52 AM Ashutosh Mishra <ashutosh...@gmail.com> wrote:
I have create update api in django,but i am not getting its api link in postman

Not sure what is the "api link" you are referring to, is it the link you expect to get in the "api summary" or is it a link you expect to get in the response of the view?
If the second, you should include it in the serializer or directly in the view response - you are only returning "success" and maybe "message" in your view
 
--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/62644d15-e1f4-4beb-ad84-0ecaadf51109n%40googlegroups.com.

Ashutosh Mishra

unread,
Oct 13, 2020, 11:54:57 PM10/13/20
to Django REST framework
can anyone see my code through teamviewer ?

Rahul Salgare

unread,
Oct 14, 2020, 12:15:28 AM10/14/20
to Django REST framework
print the urlpatterns and check what are all the urls router is registering for TotalViewSet. If you dont see an url for update, my guess is viewsets.ViewSet doesn't automatically catch the update function as its not the method of ViewSet. In this case you are trying to override update method. and if you want your router to register the url for update, you should use ModelViewSet instead of ViewSet.

Ashutosh Mishra

unread,
Oct 14, 2020, 4:37:34 AM10/14/20
to Django REST framework
buddy i have tried the way i have coded,i have got results too,but today i am not getting

Ashutosh Mishra

unread,
Oct 14, 2020, 5:59:16 AM10/14/20
to django-res...@googlegroups.com
I am getting the url while printing it

You received this message because you are subscribed to a topic in the Google Groups "Django REST framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-rest-framework/ENFa7Oa8utU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/f9482bb0-f7ca-4167-b44b-f5698f3c9047n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages