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.
- [Answer]-Django form submit not working
- [Answer]-Whether to (and how to) handle multiple many-to-many relationship through a common intermediary/join table in django?
- [Answer]-Django stopped working with mod_wsgi/apache
Source:stackexchange.com