I have following ViewSet:
class BookViewSet(DefaultsMixin, viewsets.ModelViewSet):
queryset = Book.objects.all()
serializer_class = BookSerializer
@det
{mysite}/users/{pk}/password/{id}
for this to work in my viewsets i did:
class UsersViewSet(viewsets.ModelViewSet):
queryset = User.objects.all()
serializer_class = UserSerializer
@detail_route(url_path='password')
def password(self, request,pk=None):
return HttpResponse("Wow! It Works")
from above you can retrieve id from url via pk variable.
{mysite}/users/{pk}/password/{number}
Change the above password method to
@detail_route(url_path='password/(?P[0-9]+)')
def password(self, request,pk=None, number=None):
return HttpResponse("Wow! It Again Works")