1đź‘Ť
Although I’m not sure that the approach of using the resource_name with slashes will always work for you, in order to resolve your issue you can simply change the order of the URL registration.
When register the urls, register the resource with the name “library/books” last.
The reason that you have the issue is that “library/books/shelf” is caught as the book with the pk of “shelf”. If the url patterns of the resource “library/books/shelf” will come first, they will be caught by Django before trying to resolve library/books/pk.
👤Avner Rosenan
Source:stackexchange.com