我已注释掉get_context_data
功能(下方),但在模板中,我仍然可以致电{{ object }}
,有人可以解释一下这是怎么回事吗?
# def get_context_data(self, *args,**kwargs):
# context=super(productdetailview,self).get_context_data(*args,**kwargs)
# print(context)
# print(self.kwargs.get("pk"))
# return context
这里是整个代码
class ProductDetailSlugView(DetailView):
queryset = product.objects.all()
template_name = "product/detail.html"
print(queryset)
# def get_context_data(self, *args,**kwargs):
# context=super(productdetailview,self).get_context_data(*args,**kwargs)
# print(context)
# print(self.kwargs.get("pk"))
# return context
# def get_context_data(self, *args, **kwargs):
# context=super(ProductDetailSlugView,self).get_context_data(*args,**kwargs)
# context['cart']=cart.objects.get_or_create(self.request)
# # print(context)
# return context
# def get_object(self, *args,**kwargs):
# print(args)
# print(kwargs)
# pk=self.kwargs.get("pk")
# slug=self.kwargs.get("slug")
# print(self.kwargs.get("slug"))
# print(product.objects.get_by_slug(slug))
# return product.objects.get_by_slug(slug)