Removing movies from the cart
To remove movies from the cart, we will follow the next steps:
- Configure a
clear
URL. - Defining a
clear
function. - Updating the
cart.index
template.
Configuring clear URL
In /cart/urls.py
, add the next path by adding the following lines in bold:
from django.urls import path from . import views urlpatterns = [ path('', views.index, name='cart.index'), path('<int:id>/add/', views.add, name='cart.add'), path('clear/', views.clear, name='cart.clear'), ]
We define a cart/clear/
path that will execute the clear
function defined in the views
file. We will implement the clear
function later.
Defining clear function
In /cart/views.py
, add the following lines in bold at the end of the file:
… def clear(request): request.session['cart'] = {} &...