Now that we have exposed our product data via generic views and created corresponding URL patterns, we need to implement some templates to render the product information to our browser. Another advantage of using generic views is that templates are automatically specified for each view based upon the name of the application and model in use. Since our urls.py
file is part of the products
application and we are rendering generic views on our Product model, our application will automatically look for templates in the following locations within the template folder: products/product_detail.html
and products/product_list.html
.
These templates will get rather simple contexts. The object_list
template will receive a variable whose default name is object_list
. It is a QuerySet
corresponding to the data exposed by your view. The object_detail
template will receive a variable whose default name is object
. It corresponds to the object you are viewing in more detail...