I Created a dynamic url routing/views for each one of the product on my website, Everything is working fine until I go to Cart/checkout and it loads on of the product page currently in Cart instead of Cart.html and Checkout.html
urlpatterns = {
path('<str:pk>/', views.dynamic_product_view, name='productdetail'),
}
views.py:
def dynamic_product_view(request, pk=None):
products = Product.objects.all()
slug=None
data = cartData(request)
items = data['items']
if pk is not None:
try:
slug = Product.objects.get(slug=pk)
except:
Http404()
context = {
'slug':slug,
'products': products,
'items': items
}
return render(request, 'product-details.html', context)
It's currently working fine on any other Page like index, store and Products page but the problem appear in Cart and Checkout