Creating the shopping cart view

Now it is time to create the shopping cart views. This view will render the form that we just created, and the users should be able to change the quantities for every item on the cart, as well as remove items. If the shopping cart is empty, we should show a message saying that the cart is empty.

Before we add the view, let's go ahead and open the urls.py file in gamestore/main/ and add the following URL:

 path(r'cart/', views.ShoppingCartEditView.as_view(), name='user-  cart'),

Here, we define a new URL, 'cart/', and, when accessed, it will execute the class-based view ShoppingCartEditView. We also define a name for the URL for simplicity.

We are going to create a new file called cart.html at gamestore/main/templates/main ...

Get Python Programming Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.