[Fixed]-Filter Django Queryset Based on URL Parameter

1👍

Your two views, tool_list and part_list are exact replicas of each other. You can create a single view and route multiple urls to it. Like this

def product_list(request):
    tools = Tool.objects.all()
    parts = Part.objects.all()
    return render(request, 'tool_list.html', {'tools': tools, 'parts': parts})

In your urls:

url(r'^products/tools/$', product_list, name='tool_list'),
url(r'^products/parts-supplies/$', product_list, name='part_list'),
👤v1k45

Leave a comment