jebaseelan ravi
jebaseelan ravi

Reputation: 225

How to route URL pattern with URL path separator?

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

Upvotes: 0

Views: 20

Answers (1)

K.H.
K.H.

Reputation: 1462

<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

Upvotes: 1

Related Questions