Adding movies to the cart
To allow the addition of movies to the cart, we will follow the next steps:
- Configure the
add_to_cart
URL. - Define the
add_to_cart
function. - Update the
movies.show
template.
Configuring the add_to_cart URL
In /cart/
, create a new file called urls.py
. This file will contain the path regarding the URLs of the cart app. For now, fill it in with the following:
from django.urls import path from . import views urlpatterns = [ path('<int:id>/add/', views.add, name='cart.add'), ]
We added a new path called cart/<int:id>/add
(remember that the project-level URLs file defined a /cart
prefix for this file). The <int:id>
part indicates that this path expects an integer value to be passed from the URL and that the integer value will be associated with a variable named id
. The id
variable will be used to identify which movie we want to add to the cart. For example, the cart/1/add...