May 2018
Beginner to intermediate
526 pages
11h 57m
English
Now, we need to add an Add to cart button to the product detail page. Edit the views.py file of the shop application, and add CartAddProductForm to the product_detail view as follows:
from cart.forms import CartAddProductFormdef product_detail(request, id, slug): product = get_object_or_404(Product, id=id, slug=slug, available=True) cart_product_form = CartAddProductForm() return render(request, 'shop/product/detail.html', {'product': product, 'cart_product_form': cart_product_form})
Edit the shop/product/detail.html template of the shop application, and add the following form to the product's price as follows:
<p class="price">${{ product.price }}</p><form action="{% url "cart:cart_add" product.id %}" method="post"> ...Read now
Unlock full access