我得到'对象'没有属性'对象'。这是我在views.py
中的代码def product_list(request,category_slug = None):
category = None
categories = category.objects.all()
products = Product.object.filter(available=True)
if category_slug:
category = get_object_or_404(Category, slug=category_slug)
products = products.filter(category=category)
return render(request,'shop/prod/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)
cart_product_form = CartAddProductForm()
return render(request,
'shop/prod/detail.html',
{'product': product,
'cart_product_form':cart_product_form })
答案 0 :(得分:0)
category = None
categories = category.objects.all()
您正在将类别设置为无,然后立即将类别设置为类别的属性,这只能是一个错误,因为python中的None是缺少值。
您可以在此处查看有关官方python文档的更多信息: https://docs.python.org/3/library/constants.html#None