我想在Django中显示与一个特定商店相关的所有产品吗?

时间:2020-04-11 04:47:17

标签: python django orm

Views.py

    matching_product = Product.objects.filter(shop__shop_slug=single_slug)
    return render(request, 'products/shop_products.html',{"part_ones":matching_product})

urls.py

path("<single_slug>",views.single_slug, name="single_slug")

shop_products

{% for shops in matching_product %}

shop.html(用于url) <a href="{{shop.shop_slug}}"><strong>{{shop.shop_location}}</strong></a>

它没有显示任何产品

1 个答案:

答案 0 :(得分:0)

matching_product = Product.objects.filter(shop__shop_slug = single_slug)

首先,调试上面的行。有结果吗?