I've got the message Reverse for 'receptionop-list' not found. 'receptionop-list' is not a valid view function or pattern name.
in one of my test cases when trying to do the following:
reverse('receptionop-list')
Note: I have also tried reverse('receptionops-list')
I've got it set in my urls like this:
router.register(r'receptionops', views.ReceptionOperationViewSet)
What's weird for me, is the fact I've got also a router.register(r'reception', views.ReceptionViewSet)
registered in the same app, and using reverse('reception-list')
works perfectly.
Does anyone know what's going on here?
(If needed, I can provide some further information)
Thanks!
FIXED
The problem here, is that I was trying to target the wrong basename 'receptionops'
. Reading the Django REST framework documentation (https://www.django-rest-framework.org/api-guide/routers/) I found the explanation:
basename - The base to use for the URL names that are created. If unset the basename will be automatically generated based on the queryset attribute of the viewset, if it has one. Note that if the viewset does not include a queryset attribute then you must set basename when registering the viewset.
Here's the queryset field of my ReceptionOperationViewSet
:
queryset = ReceptionOperation.objects.all()
So, in this case, I should have used the following:
reverse('receptionoperation-list')
And now it's working just fine!
Aucun commentaire:
Enregistrer un commentaire