10. View product page
path('product/<int:product_id>', view_product, name="view_product"),def view_product(request, product_id) :
product = Product.objects.get(id=product_id) #? id parameter is created automatically by django
context = {'product': product}
return render(request, 'view_product.html', context){% extends 'base.html' %}
{% load static %}
{% block body %}
<h3>
{{ product.name }}
</h3>
<img src="{{ product.image.url }}" width = "300" height = "450"> <!--returns the url of the image -->
<p>Product: {{ product.name }}</p> <!-- Originally, what will be displayed in product is what is returned in its respective __str__ function on the models file-->
<p>Price: {{ product.price }}</p>
<button>Add to Cart</button>
{% endblock %}

Last updated