Creating the purchase page
Let’s improve our shopping cart page and include some functionalities to allow users to make purchases. To achieve that, we need to follow these steps:
- Configuring the purchase URL.
- Defining the
purchase
function. - Updating the
cart.index
template. - Creating the
cart.purchase
template.
Configuring the purchase URL
In /cart/urls.py
, add the next path as shown 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'), path('purchase/', views.purchase, name='cart.purchase'), ]
We defined a cart/purchase/
path that will execute the purchase
...