The current path,didn't match any of these

3

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

answered question

B0882NKXW7 is not a valid uuid, an uuid is for example 2707820f-5182-407d-9c07-ff7845807d4c.

Then how to get this B0882NKXW7 ?

well the question is where your B0882NKXW7 comes from? It looks like this is somehow encoded in the template/view/... You can use <str:puid> to accept the B088....

Thanks. I use str:puid and it works for me. Thanks a lot.

2 Answers

6

I replace the URL path

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

posted this
2

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),
]

posted this

Have an answer?

JD

Please login first before posting an answer.