Listing movies added to the cart
To allow us to list movies added to the cart, we will follow the next steps:
- Configure the cart index URL.
- Define a
utils
file. - Define a filter.
- Define an
index
function. - Creating the
cart.index
template. - Updating the
add_to_cart
function. - Adding a link in the base template.
Configuring cart index URL
In /cart/urls.py
, add the next path by adding the 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'), ]
We defined a ''
path but remember that the project-level URL file defined a /cart
prefix for this file. So, if a URL matches the /cart
path, it will execute the index
function defined in the views
file. We will implement the index
function later.
Defining a utils file
Commonly...