I'm making a shopping cart app for my website, and the function that worked yesterday was broken today.
I got Reverse for 'delete-cart' with arguments '(4,)' not found. 1 pattern(s) tried: ['cart/delete_cart/<int:pk>']error, But you can see that it has displayed the value of the parameter, proving that it got the value but still returned the not found error, why?
Here is my relevant code:
urls.py
urlpatterns = [
path('',views.myCartListView,name='my-cart'),
url(r'^delete_cart/<int:pk>',views.delete_cart,name='delete-cart'),
]
views.py
@login_required
def myCartListView(request):
context = {}
if request.user:
data = Cart.objects.filter(client=request.user)
context['cart'] = data
return render(request,'cart/my_cart.html',context)
@login_required
def delete_cart(request,pk):
record = Cart.objects.get(pk=pk)
record.delete()
return redirect('cart/')
my_cart.html
{% for c in cart %}
<tr>
<th>{{c.item}}</th>
<th>{{c.quantity}}</th>
<th>{{c.price}}</th>
<th>{{c.get_total_price}}</th>
<th><a href="{% url 'delete-cart' c.id %}">DELETE</a></th>
</tr>
{% endfor %}