I am following along the code on the Chapter. Everything else before the product detail page worked as expected but the product detail page failed to load any data associated with any product (see image) on clicking any product on the product listing page. The click redirects to the product details page, however the appropriate data doesn't load. Any help would be appreciated.
The detail.html file inside "/templates/shop/product" is exactly the same as the code on page [236-237] of the text and the appropriate file on GitHub. Below is the code for reference...
The views.py code is:
`from django.shortcuts import render, get_object_or_404
from .models import Category, Product
Realized the error that was causing it -- the product object that was passed onto get_object_or_404 on the views.py should have been 'product' instead of 'Product'.
Hi,
I am following along the code on the Chapter. Everything else before the product detail page worked as expected but the product detail page failed to load any data associated with any product (see image) on clicking any product on the product listing page. The click redirects to the product details page, however the appropriate data doesn't load. Any help would be appreciated.
The detail.html file inside "/templates/shop/product" is exactly the same as the code on page [236-237] of the text and the appropriate file on GitHub. Below is the code for reference...
The views.py code is: `from django.shortcuts import render, get_object_or_404 from .models import Category, Product
def product_list(request, category_slug=None): category = None categories = Category.objects.all() products = Product.objects.filter(available=True) if category_slug: category = get_object_or_404(Category, slug=category_slug) products = products.filter(category=category) return render(request, 'shop/product/list.html', {'category': category, 'categories': categories, 'products': products})
def product_detail(request, id, slug): product = get_object_or_404(Product, id=id, slug=slug, available=True)
and the urls.py code in the app folder is: `from django.urls import path from . import views
app_name = 'shop'
urlpatterns = [ path('', views.product_list, name='product_list'), path('/', views.product_list,
name='product_list_by_category'),
path('//', views.product_detail,
name='product_detail'),
]`