The current path,didn't match any of these

1.2k views Asked by At

I have this in urls.py

urlpatterns = [
path("product/<str:title>/<slug:pname>/<uuid:puid>",views.viewProduct),
]

But when I try to click on the url. I got this error.

The current path, product/amazon/home-secure-snake-shield-natural-snake-r/B0882NKXW7, didn't match any of these.

Here I just want the puid but to match the pattern of URL I added str:title and str:pname

I don't want the title and pname. But my URL patern is like this-

product/store_name/product_name_slug/product_id
2

There are 2 answers

0
suraj sharma On BEST ANSWER

I replace the URL path

urlpatterns = [
path("product/<str:title>/<slug:pname>/<str:puid>",views.viewProduct),
]
0
willeM_ Van Onsem On

The B0882NKXW7 is not a valid format for a UUID [wiki]. Indeed, a UUID is typically represented as 16 octets. For example 2707820f-5182-407d-9c07-ff7845807d4c is a UUID.

You can either define your own path converter [Django-doc] to accept your product id, or you can make use of str::

urlpatterns = [
    path('product/<str:title>/<slug:pname>/<str:puid>', views.viewProduct),
]