【发布时间】:2026-01-01 13:15:01
【问题描述】:
我正在为产品类别创建过滤器,并希望从我的模板上的相应图像中传递类别名称。 部分过滤栏:
<a href="{% url 'product-filter' MISC%}">
<img src="{% static 'store/images/skateboard.png' %}" alt="">
</a>
网址:
path('search/<category>/', store_views.product_filter ,name='product-filter'),
我希望模板中的 MISC 通过并成为类别,以便我可以在视图中使用它:
# ? Filter Products by Catagory
def product_filter(request, category):
products= Product.objects.all()
filter=ProductFilter(category,queryset=products)
context={'products':filter}
return render(request,'store/filter.html',context)
目前即使在我的主页上也能看到:
NoReverseMatch at /
Reverse for 'product-filter' with arguments '('',)' not found. 1 pattern(s) tried: ['search/(?P<category>[^/]+)/$']
当在 /search/MISC 上时:
NoReverseMatch at /search/MISC/
Reverse for 'product-filter' with arguments '('',)' not found. 1 pattern(s) tried: ['search/(?P<category>[^/]+)/$']
【问题讨论】:
标签: python django django-views django-templates