Issue
I have to route the following URL pattern to view api/v1/{resourceId}/owners
in DRF
But the problem is resourceID
contains /
in it. eg api/v1/somethings/value/owners
the additional /
causing get 404 resource not found exception
Is there way to route the URL and get resourceID
in view
My urls.py
path('api/v1/<str:resource_id>/owners', ResourceOwnershipView.as_view())
views.py
class ResourceOwnershipView(APIView):
def get(self, request: HttpRequest, resource_id: str) -> Response:
# do something with resourceID
Solution
<str:>
probably doesn't allow slashes in it. I would try to use regular expression version of routing definition re_path
:
https://docs.djangoproject.com/en/4.1/ref/urls/#re-path
Answered By - K.H.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.