I've tried changing the name_icontains to name_iexact in the def product_view but then it stops working completely, am I missing something very obvious?
That might be because product name that you searched does not exactly match with the one stored.
If you want to do approximation/fuzzy search you can use __icontains()
, but use only one search result.
Sample code:
try:
category = Category.objects.get(name__iexact=category_name)
#use .filter()
product = Product.objects.filter(name__icontains=product_name)[0]
context_dict['category'] = category
context_dict['product'] = product
except IndexError:
#product does not exists
pass