Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading