[Answer]-Django, Product matching query does not exist

1👍

Try this:

url(r'^products/(?P<slug>[a-zA-Z0-9_-]+)/$', 'products.views.single', name="single_product")

.* means “is not required”.

Also I recommend you to take a look at DetaiView which can handle 404 and stuff

class ProductView(DetailView):
    model = Product
    template_name = 'products/single.html'
    context_object_name = 'product'

single = ProductView.as_view()

That’s it!

0👍

Regex should be like this: (?P<slug>\w+) (I assume that in model it is charfield).

Your regex gives two matches instead of one, the second match is empty.

After that make sure that object with that slug exists in database.

Leave a comment