A parameter in the url ViewSet?

router.register(R 'my_api', MyViewSet)


class MyViewSet(viewsets.ModelViewSet):
 queryset = MyModels.objects.all()
 lookup_field = 'slug' # < add/delete this option also does not help

 def get_serializer(self, *args, **kwargs):
 if self.action == 'my_action':
 return MySerializer(*args, **kwargs)

 def my_action(self, request, **kwargs):
 print(kwargs['slug']) # <-- here needs to myslug

 def other_action(self, request, **kwargs):
 # then I slug not needed, and not necessary in the url to transfer

When you request /my_api/myslug/my_action/ I need the value of the slug is transmitted only in the my_action.
Now writes that there is no such url
router.register(R 'my_api', MyViewSet)
router.register(R my_api/(?P<slug>\w+)/', MyViewSet)</slug>

doesn't help
June 8th 19 at 17:22

Find more questions by tags DjangoRESTful API